Click here to Skip to main content
15,893,722 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want show sql serach result in several textboxes(for example my serach have 4 record and every record have 5 fiels i want show one field in one textbox)
Posted
Comments
OriginalGriff 25-Jul-13 9:42am    
Sorry, but that doesn't make a whole lot of sense: if you have four records, and five columns per record than you would need a variable number of textboxes in order to display the full results.

A better approach might be to have a grid control showing all the rows, and textboxes to show only the currently highlighted row data.

1 solution

This is easy to do. If you have a SQL helper class use that or you can use the SqlCommand object and the SqlDataReader along with the SqlConnection.

Something similar to:
C#
 dr = cmd.ExecutReader();
if (dr.HasRows)
{
  dr.Read();
  textbox1.Text = dr["FirstField"].ToString();
  textbox2.Text = dr["SecondField"].ToString();
}


so on and so forth.
 
Share this answer
 
Comments
mekameka 26-Jul-13 2:54am    
ok-if we have 1 record for result search it is true but search result have more than 1 record for use 2th record
in textbox 3 and textbox 4 (for example) what is code ?
ZurdoDev 26-Jul-13 7:32am    
dr.Read() advances to the next record.

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