Click here to Skip to main content
12,815,592 members (41,000 online)
Rate this:
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 2:04am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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


RaviRanjankr 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 3 Sep 2011
Copyright © CodeProject, 1999-2017
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