Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I show sql query in some textboxes regularly I mean my query has for example 3 answer and I want to show them in 3 textboxes,can I use ExecuteScalar or use Listbox or recordset?how can I do this?I think I should use a loop but how?
Posted
Comments
Amir Mahfoozi 30-Oct-11 5:45am    
What do you mean by saying 3 answers ? 3 rows with 0ne field or 1 row with three fields ?

1 solution

// Create the connection and connect then execute sql statement

string str = "SELECT EmployeeID, FirstName, LastName FROM  Employees";

SqlCommand myDataReader = new SqlCommand(str, con);

myDataReader.Read();

if (myDataReader.HasRows)
{
  while (myDataReader.Read())
  {
    txtFName.Text = myDataReader.GetString("FName").ToString();
    txtLName.Text = myDataReader.GetString("LName").ToString();
    txtNName.Text = myDataReader.GetString("EmployeeID").ToString();

  }
}
// Nothing was found based on Search Criteria, Tell the System
else
{
  MessageBox.Show("No matches were found, try again.");
}
  myDataReader.Close();



Regards.
 
Share this answer
 
v3

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