Click here to Skip to main content
15,898,010 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Can anyone explain me following c# code in step by step:

public void update(string id)
   {
       string ids = Request.QueryString["ids"];
       Session["ID"] = ids.ToString();
       con.Open();
       SqlCommand cmd = new SqlCommand("select * from product where pro_id='" + ids + "'", con);
       SqlDataReader dr = cmd.ExecuteReader();
       if (dr.HasRows)
       {
           while (dr.Read())
           {
               txtpro_id.Text = dr["pro_id"].ToString();
               txtpro_name.Text = dr["pro_name"].ToString();
               txtdescription.Text = dr["description"].ToString();
               txtpriority.Text = dr["priority"].ToString();
               txtytubeurl.Text = dr["ytube_url"].ToString();
               txtprice.Text = dr["price"].ToString();
           }
           dr.Close();
       }
       con.Close();
Posted

1 solution

1-
C#
public void update(string id)

you writting a method by pasing one parameter as String Id

2-
C#
string ids = Request.QueryString["ids"];

you storing value in 'ids' from QueryString that come from somewhere like you passing value from one page to another using QueryString

3-
C#
Session["ID"] = ids.ToString();

you storing QueryString value in session

4- con.Open();
opening the connention by calling the connectionString value.

5-
C#
SqlCommand cmd = new SqlCommand("select * from product where pro_id='" + ids + "'", con);

firing the Query and Storing in SQLCommant Property

6-
C#
SqlDataReader dr = cmd.ExecuteReader();

executing the command using SQlDataReader. Data reader is read only one row and discard all other row

7-
C#
if (dr.HasRows)

HasRows is used to check dr has row or not.if dr contain row then it will go inside the loop

8-
C#
while (dr.Read())
            {
                txtpro_id.Text = dr["pro_id"].ToString();
                txtpro_name.Text = dr["pro_name"].ToString();
                txtdescription.Text = dr["description"].ToString();
                txtpriority.Text = dr["priority"].ToString();
                txtytubeurl.Text = dr["ytube_url"].ToString();
                txtprice.Text = dr["price"].ToString();
            }




setting the value to the control one by one

9-
C#
dr.Close();

closing the datareader

10-
C#
con.Close();

closing the connection
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900