Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
How to bind textbox from database. Ex- i have fields in database i want bind all in five textbox.
Posted 3-Sep-11 1:04am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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");
  Permalink  
Comments
koolprasad2003 at 3-Sep-11 7:24am
   
to the point, 5!
Azeem. at 30-Oct-13 7:47am
   
Please tell that How to write back into database if text is changed in textBox1 ??
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
 
}
 
  Permalink  
Comments
RaviRanjankr at 3-Sep-11 23:53pm
   
Good Answer, My 5+

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 505
1 OriginalGriff 258
2 ChintanShukla 195
3 Bhavik_Patel 170
4 Richard Deeming 165
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 3 Sep 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100