简体   繁体   中英

Display Query Values in Individual Textboxes

How can I show SQL query results in text boxes, such that for a query with three answers, I want to show them in three text boxes? Can I use ExecuteScalar or Listbox or recordset? How can I do this? I think I should use a loop but how?

If you are executing a SQL command that returns a result, such as executing a SELECT statement you will have to use a different method. The SqlCommand's ExecuteReader method returns a SqlDataReader object that contains all of the records retrieved after executing the SQL command If you are executing a SQL command that returns a result, such as executing a SELECT statement you will have to use a different method. The SqlCommand's ExecuteReader method returns a SqlDataReader object that contains all of the records retrieved after executing the SQL command .

try
{
  SqlDataReader dr;
  dbCon.Open();

 //write your select statement here.....
  dr = sqlcom.ExecuteReader();
  if(dr.HasRows == True)
  {
    txt_clientID.Text = ((Integer) dr["cID"]).ToString();
    txt_clientAddress.Text = (String) dr["cAddress"];
    txt_clientPhoneNumber.Text = (String) dr["cPhoneNumber"];
  }
  dr.Close();
  dbCon.Close();
}
catch(Exception ex)
{} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM