Java |
Winforms update help??
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
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.

Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 10, 2010, 1:43 AM EST
myDataRow["CustomerId"] = "NewID";
myDataRow["ContactName"] = "New Name";
myDataRow["CompanyName"] = "New Company Name";
myDataSet.Tables["Customers"].Rows.Add(myDataRow);
myDataSet.AcceptChanges();
SqlCommandBuilder mySqlCommandBuilder = new SqlCommandBuilder(mySqlDataAdapter); mySqlDataAdapter.Update(myDataSet, "Customers"); And Here your Dataset will be updated from gridview. Similarly you can Delete/Edit from the grid view with respect to add code to their events.Please mark as answer if it helps you.
chandu12 reputationPosted Mar 10, 2010, 1:56 AM EST
**Object reference not set to an instance of an object.i dnt know why im getting this error any help??
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 10, 2010, 2:02 AM EST
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);
chandu12 reputationPosted Mar 10, 2010, 3:01 AM EST
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 10, 2010, 8:12 PM EST
For your code needs primary key of the table. If your table doesn't have a primary key, you need to make one
thanks
chandu12 reputationPosted Mar 10, 2010, 8:49 PM EST
Hirendra SisodiyaRank #258 · 9.8K reputationPosted Mar 11, 2010, 6:52 PM EST