Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i retrieving database values in textbox in page load
C#
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from Employee", cn);
DataSet ds = new DataSet();
da.Fill(ds);
TextBox1.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox2.Text = ds.Tables[0].Rows[0][2].ToString();
TextBox3.Text = ds.Tables[0].Rows[1][1].ToString();
TextBox4.Text = ds.Tables[0].Rows[1][2].ToString();
TextBox5.Text = ds.Tables[0].Rows[2][1].ToString();


it will show the database values in textbox. now i want to edit textbox text and after click the update button databsae table should be update .
please help me
Posted
Updated 2-Sep-13 10:27am
v3
Comments
OriginalGriff 2-Sep-13 14:54pm    
And what part of this is giving you problems? What have you tried? Where are you stuck?
What help do you need?
[no name] 2-Sep-13 15:01pm    
If your goal is to update the database why don't you show us that code instead of this code that has nothing to do with what you are trying to accomplish?

Please use Data binding for a better approach, or create a new SQL command for update, and pass all your textboxes values to the command and call execute update like this:

C#
public bool ExecuteCommand ()
{
   using (sqlConnection)
   {
      try
      {
         sqlConnection.Open();
         using (var sqlCommand = new SqlCommand(CommandText, sqlConnection))
         {
             sqlCommand.CommandText = 'your update cmd';
             
             sqlCommand.ExecuteNonQuery()
         }
      }
      catch (Exception)
      {
         //Handle Exception Here
      }

   }
}
 
Share this answer
 
Follow question ans answer of this thread carefully:
How to display data from database into textbox, and update it[^]
 
Share this answer
 
Write Update function for your textbox value like
C#
public int update_Record()
       {
           DB_Connection();
           int i;
           string QRY = "UPDATE personalInfo_Master SET village='" + Village + "', taluka='" + Taluka + "',dist='" + District + "',state='" + State + "'WHERE name='" + Name + "'";
           SqlCommand CMD = new SqlCommand(QRY, con);
           i = CMD.ExecuteNonQuery();
           return i;
       }
 
Share this answer
 
you can visit on belowing page for More Details of your question on code project. That one also ask same as you


Save data from textbox to database[^]
 
Share this answer
 

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