hi all i have created a datagridview to display my records from db,and now i want to update the records below shown is my code
SqlDataAdapter da = new SqlDataAdapter("select * from emp", con); SqlCommandBuilder cb = new SqlCommandBuilder(da); DataSet ds = new DataSet(); dataGridView1.DataSource = ds.Tables[0]; da.UpdateCommand = cb.GetUpdateCommand(); da.Update(ds);
|
but when i execute the code and update the values they are not getting updated in my database??i dnt know y?? plz help me with this,thanks.
Hirendra SisodiyaPosted Mar 11, 2010, 11:52 PM
chanduPosted Mar 11, 2010, 1:49 AM
Hirendra SisodiyaPosted Mar 11, 2010, 1:12 AM
For your code needs primary key of the table. If your table doesn't have a primary key, you need to make one
thanks
chanduPosted Mar 10, 2010, 8:01 AM
Hirendra SisodiyaPosted Mar 10, 2010, 7:02 AM
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
OleDbCommandBuilder cBuilder = new OleDbCommandBuilder(dAdapter);
DataTable dTable = new DataTable();
dAdapter.Fill(dTable);
BindingSource bSource = new BindingSource();
bSource.DataSource = dTable;
DataGridView1.DataSource = bSource;
dAdapter.Update(dTable);
chanduPosted Mar 10, 2010, 6:56 AM
**Object reference not set to an instance of an object.i dnt know why im getting this error any help??
Amit ChoudharyPosted Mar 10, 2010, 6:43 AM
Please mark as answer if it helps you.