Click here to Skip to main content
15,902,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to bind textbox from database. Ex- i have fields in database i want bind all in five textbox.
Posted

C#
SqlDataAdapter objAdpt = new SqlDataAdapter("select * from testtable", myConnection);

DataSet objDS = new DataSet();
objAdpt.Fill(objDS, "testtable ");

if (objDS.Tables[0].Rows.Count > 0)
{

  txt1.Text = objDS.Tables[0].Rows[0]["ColumnName"].ToString();
  txt2.Text = objDS.Tables[0].Rows[0]["ColumnName"].ToString();

}
 
Share this answer
 
Comments
RaviRanjanKr 3-Sep-11 23:53pm    
Good Answer, My 5+
Try:
SqlConnection con = new SqlConnection(connString);
SqlDataAdapter da = new SqlDataAdapter(@"SELECT * FROM Employees ", con);
DataSet ds = new DataSet();
da.Fill(ds, "Employees");
textBox1.DataBindings.Add("text", ds, "Employees.firstname");
textBox2.DataBindings.Add("text", ds, "Employees.lastname");
 
Share this answer
 
Comments
koolprasad2003 3-Sep-11 7:24am    
to the point, 5!
DoingWork 30-Oct-13 7:47am    
Please tell that How to write back into database if text is changed in textBox1 ??

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