Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In DataGridView i have some values...

and i have a button UPDATE...

if i edit some data in that gridview...and click that Update button...that edited data is stored in the Database...How can i do it.

Thanks in advance.
Posted
Updated 8-Nov-11 0:23am
v8
Comments
Abdul Rahman Hamidy 8-Nov-11 2:18am    
did you try google?
Sam Path 8-Nov-11 2:20am    
Ya i tried but i cant get result...

Are you looking for an auto-save feature - then see Auto Saving DataGridView Rows to a SQL Server Database[^].

Here[^] is a decent startup article for DataGridView save.
This[^] may help you as well.
 
Share this answer
 
add a hidden column in datagridview
set its to true on 'cellvaluechanged' event
now u can update only those rows by looping the datagridview
 
Share this answer
 
very simple: you have some values in datagridview, so now you create one buttons write the following coding within the button.

for(int i=o;i<datagridview1.rows.count-1;i++)
{
string a = dataGridView1.Rows[i].Cells["o_no"].Value.ToString();
string b = dataGridView1.Rows[i].Cells["c_name"].Value.ToString();
string c = dataGridView1.Rows[i].Cells["date"].Value.ToString();
string d = dataGridView1.Rows[i].Cells["kgs"].Value.ToString();

string query = "UPDATE yourtablename SET o_no='" + a + "',c_name='" + b + "',date='" + c + "',kgs='" + d + "' where o_no='" + a + "'";
OleDbConnection con = new OleDbConnection("yourdatabasepath");
con.Open();
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
}
messagebox.show("successfully edited on database");
//now you executed your project.
 
Share this answer
 
v4
you can temporary store data to datatable which is easy...


C#
Datatable dt=new DataTable();
dt=griedView1.Source;
 
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