Click here to Skip to main content
15,905,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,

I have two textboxes and one button. With these textboxes I am inserting some values to gridview. In this process I am creating datatable and datarow and fill up the gridview. It is working perfectly.
My requirememnt is how can I save these values inserting though datatable in database.

If any body knows, please tell me.
Thank you.
Posted
Updated 26-Dec-10 0:27am
v2
Comments
JF2015 26-Dec-10 6:27am    
Edited to improve spelling and grammar.

This[^] may help.
 
Share this answer
 
Comments
Dalek Dave 28-Dec-10 2:05am    
Good Link.
you can use given Command Format to save your Data using Datatable.

SqlCommand cmd = new SqlCommand("Command ", Connection);
      SqlDataAdapter da = new SqlDataAdapter();
      da.SelectCommand = cmd;
      SqlCommandBuilder cmdbuilder = new SqlCommandBuilder(da);
      DataSet ds = new DataSet();
      da.Fill(ds, "TableName");
      DataTable dt = ds.Tables["TableName"];
      DataRow  dr = dt.NewRow();
      dr[index] = textbox1.Text;
      dr[index] = textbox2.Text;
      dt.Rows.Add(dr);
       da.Update(ds, "TableName"); // Saves Data
 
Share this answer
 
v2
Comments
Dalek Dave 28-Dec-10 2:05am    
Good 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