Calling the data by typring the id in textbox

This blog shows that how can we show the data of sql table in textboxes by just typing the id in one textbox__

Code
: Type this code on the button_click event

          string productCode;
            productCode = textBox1.Text;
//
You have to give the textbox where you enter the ID

            SqlCommand cmd = cn.CreateCommand();
            cmd.CommandType = CommandType.Text;        
            cmd.CommandText = "select * from ProductDetails where ProductId=@Pode";

 // Here ProductDetails is table name and ProductId is column name

            cmd.Parameters.Add(new SqlParameter("@Pode", productCode));
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                textBox2.Text = Convert.ToString((dr[1]));
                textBox3.Text = Convert.ToString((dr[2]));

//you can take more textboxes as per your table records

            }

Thanks

Nikhil Kumar
Ebook Download
View all
Learn
View all