Archive for 2016

Using Ajax Control Toolkit in ASP.NET

Download Ajax Control Tool Kit from below link

Ajax control toolkit download link
Extract The file then Go To Visual Studio 
Open Tool Box
Right Click On The Existing Tab
And Click On Add New Tab 
Name the tab
Right click on the newly tab
click on choose all items
Template Will Be Open And Select Browse Go To The Location
And Select AjaxControlTOolkit.dll  
Click Open It Will Open Security PopUp Window - Select Yes
Ajax controls will be added in toolbox which can be used to extend the existing functionality of ASP.NET controls.

Wednesday, 14 December 2016
Posted by Sudhir Chekuri
Tag :

ASP.NET Controls



Wednesday, 7 December 2016
Posted by Sudhir Chekuri
Tag :

ASP.NET Master Pages

Master pages are used to create common layout for multiple websites.
Master pages will have .master as page extension and we can see output of master page directly.
Multiple web forms(.aspx pages) can be created using single master page. All these web forms will inherit the UI and functionality from its master page.
Output of the master page can be tested by testing its child pages which inherits its master page UI and functionality.

When multiple pages are created using a master page, Common UI and behavior of all the web forms can be controlled from master pages.


Sunday, 4 December 2016
Posted by Sudhir Chekuri
Tag :

Introduction to ASP.NET

ASP.NET is a technology under .NET Framework which is used to create web sites.
ASP stands for Active Server Pages.

HTML, CSS and javascript are used as basic building blocks for developing websites using ASP.NET.

C#.NET will act as a code behind language along with ASP.NET to implement the functional logic of websites.

Monday, 28 November 2016
Posted by Sudhir Chekuri
Tag :

SQL Injection

Hacking database by entering input data which maninpulates sql queries is

known as sql injection.

Example:

Expected: select * from tbl_data where name='admin' and pwd='password'
Hacked: select * from tbl_data where name='admin' and pwd=' or 'a'='a'

With sql injection attacker may overwrite or delete data in database, can make app to behave in a different way.


SQL injection can be done using post and get parameters, cookie values, form fields and header values.

Parmeterized sql queries will help in controlling sql injection.

In .NET - > ADO.NET -> SQL queries using parameters(@name) to append values in query is recommended.


Input client side validations will also mitigate sql injection issues.

stored procedures will reduce sql injection.


Sunday, 27 November 2016
Posted by Sudhir Chekuri

C#.NET ref and out parameters with example

ref stands for reference and out stands for output.

ref parameter variable should be initialized before we call the method. That value will be used a as reference value in the method.

out parameter variable initialization is not required but it should be returned by the method.

Example program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FirstConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            //val1 has to be initialized
            int val1 = 10;
            p.Add(ref val1);
            //val2 initialization not required
            int val2;
            int j = p.Sub(out val2);
            Console.WriteLine(j);
            Console.ReadKey();

        }

        public void Add(ref int val1)
        {            //code goes here
            Console.WriteLine("Hello");
        }
        public int Sub(out int val2)
        {
//val2 is changed from 2 to 5
            val2 = 5;
            return val2;
        }
    }
}

Output:
Hello
5


Tuesday, 31 May 2016
Posted by Sudhir Chekuri

Stored Procedures in ADO.NET

// 1. create a command object identifying
        // the stored procedure
        SqlCommand cmd  = new SqlCommand(
               "CustOrderHist", conn);
 
        // 2. set the command object so it knows
        // to execute a stored procedure
        cmd.CommandType = CommandType.StoredProcedure;
 
        // 3. add parameter to command, which
        // will be passed to the stored procedure
        cmd.Parameters.Add(
               new SqlParameter("@CustomerID", custId));



Saturday, 12 March 2016
Posted by Sudhir Chekuri
Tag :

Disconnected Architecture Delete

//Disconnected architecture - delete
        //Delete product
        private void BtnDeleteProduct_Click(object sender, EventArgs e)
        {
             //SqlCommand to delete Product
            SqlCommand cmd = new SqlCommand("exec Usp_DeleteProduct '"+CBExistingCategories.Text+"','"+CBExistingProducts.Text+"'", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            //Update Products
            PopulateProducts();
            //Clear product details
            TxtDescription.Text = "";
            NudPrice.Value = 1;
                MessageBox.Show("Product Deleted Successfully");
           

        }


Posted by Sudhir Chekuri
Tag :

Disconnected Architecture Update

//Disconnected - update
        //Update product name based on the product name under a category
        private void BtnUpdateProduct_Click(object sender, EventArgs e)
        {
            //SqlCommand to delete Product
            SqlCommand cmd = new SqlCommand("exec Usp_UpdateProduct '" + CBExistingCategories.Text + "','" + CBExistingProducts.Text + "','"+TxtUpdateProduct.Text+"'", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            //Update Products
            PopulateProducts();
            //Show first item
            CBExistingProducts.SelectedIndex = 0;
            MessageBox.Show("Product Updated Successfully");
          
        }
        //Disconnected Update
        //Update product details
        private void BtnAddDetails_Click(object sender, EventArgs e)
        {
            //exec Usp_AddProductDetails 'Drinks','Sprites','200 ml sprite chota bottle',25
            //SqlCommand to delete Product
            SqlCommand cmd = new SqlCommand("exec Usp_AddProductDetails '" + CBExistingCategories.Text + "','" + CBExistingProducts.Text + "','" + TxtDescription.Text + "',"+NudPrice.Value+"", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
            MessageBox.Show("Product details added Successfully");

        }


Posted by Sudhir Chekuri
Tag :

Disconnected Architecture Insert

//Disconnected Insert
        //Adding product
        private void BtnAddProduct_Click(object sender, EventArgs e)
        {
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
            //SqlCommand to insert Product
            SqlCommand cmd = new SqlCommand("exec Usp_InsertProduct '" + CBExistingCategories.Text + "','" + TxtAddProduct.Text + "','" + TxtDescription.Text + "'," + NudPrice.Value+ "", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
                MessageBox.Show("Product Added Successfully");
         

        }



Posted by Sudhir Chekuri
Tag :

Disconnected Architecture Select

//Disconnected - Select
        //Populate the datagridview with registered users information
        public void GetData()
        {
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
            //SqlCommand to insert Category
            SqlCommand cmd = new SqlCommand("select * from Tbl_Register", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds, "Users");
          
            //Display users table in DataGridView
            DGVUsers.DataSource = ds.Tables["Users"];
        }
//Disconnected - select
        //Populate Products
        public void PopulateProducts()
        {
SqlConnection con =new SqlConnection (@"Data Source=DESKTOP-LEBFFH4\PRESS;Initial Catalog=STUDENT;Integrated Security=True");
            //SqlCommand to get products
            SqlCommand cmd = new SqlCommand("exec Usp_GetProducts '"+CBExistingCategories.Text+"'", con);
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds,"Products");
            //Clear existing Products
            CBExistingProducts.Items.Clear();
            //Adding Products to combobox
           
                for(int i=0;i<ds.Tables["Products"].Rows.Count;i++)
                {
                    //Add categories to Combobox
                    CBExistingProducts.Items.Add(ds.Tables["Products"].Rows[i]["ProductName"]);
                }

        }



Posted by Sudhir Chekuri
Tag :

DataSet

DataSet is used in disconnected architecture to store database tables. It can hold multiple tables in it. It is used to store information retrieved by DataAdapter in disconnected architecture. Data adapter will execute the command and fill the dataset with the data retrieved by execution of SQL command.

Posted by Sudhir Chekuri
Tag :

DataAdapter

DataAdapter is used to disconnected architecture to execute all the commands. It is capable of opening the connection to the database server, executing the command, Storing data in DataSet and closing the connection.


Posted by Sudhir Chekuri
Tag :

Connected Architecture Delete

//Connected architecture - delete
        //Delete Category
        private void BtnDeleteCategory_Click(object sender, EventArgs e)
        {

            //SqlCommand to delete Category
            SqlCommand cmd = new SqlCommand("exec Usp_DeleteCategory '" + CBExistingCategories.Text + "'", con);
            //Open connection
            con.Open();
            //Execute delete command
            int i = cmd.ExecuteNonQuery();
            con.Close();

            if (i > 0)
            {
                //Refresh Category list
                PopulateCategories();
                MessageBox.Show("Category Deleted Successfully");

            }
            else { MessageBox.Show("Category Not Deleted"); }

        }


Posted by Sudhir Chekuri
Tag :

Connected Architecture Update

//Connected Architecture - update
        //Update Category
        private void BtnUpdateCategory_Click(object sender, EventArgs e)
        {
            //SqlCommand to update Category
            SqlCommand cmd = new SqlCommand("exec Usp_UpdateCategory '"+CBExistingCategories.Text+"','"+TxtUpdateCategory.Text+"'", con);
            //Open connection
            con.Open();
            //Execute update command
            int i = cmd.ExecuteNonQuery();
            con.Close();

            if (i > 0)
            {
                //Refresh Category list
                PopulateCategories();
                //Show first Category
                CBExistingCategories.SelectedIndex = 0;
                MessageBox.Show("Category Updated Successfully");

            }
            else { MessageBox.Show("Category Not Updated"); }
           
        }


Posted by Sudhir Chekuri
Tag :

Connected Architecture Insert and Select



SQL Command to create SQL table

CREATE TABLE [dbo].[Tbl_Data](
       [Id] [int] IDENTITY(1,1) NOT NULL,
       [UserName] [varchar](50) NULL,
       [EmailId] [varchar](50) NULL,
       [Password] [varchar](50) NULL,
PRIMARY KEY CLUSTERED
(
       [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

------------

ADO.NET C# code to insert data into SQL database table and to view the data
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace mani
{
    public partial class home : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Btn_Insert_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-R72EIR5\SQLEXPRESS;Initial Catalog=mk;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("insert Tbl_Data(Username,EmailId,Password) Values('" + Txt_UserName.Text + "','" + Txt_EmailId.Text + "','" + Txt_Password.Text + "')", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Txt_UserName.Text = "";
            Txt_EmailId.Text = "";
            Txt_Password.Text = "";
            Response.Write("inserted Successfully");

        }

        protected void Btn_Select_Click1(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-R72EIR5\SQLEXPRESS;Initial Catalog=mk;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("Select * From Tbl_Data", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            GV_Select.DataSource = ds;
            GV_Select.DataBind();

        }
    }
}

Posted by Sudhir Chekuri
Tag :

Followers

Total Pageviews

Powered by Blogger.

- Copyright © 2013 DevStudent - Metrominimalist - Powered by Blogger - Designed by Johanes Djogan -