How to update the database when data on a datagrid has changed?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I have a datagrid and its source is a dataset. When I change information
on the grid does that automatically gets change in the dataset? If not then
how do I do that? I use the following update statement when the form is
closed to udpate the database but the changes are not there.
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");

Thanks, Alpha
 
Hi,
You could try

dsVehicle.Tables[ "vehDetail" ].RowChanged +=
new DataRowChangeEventHandler(dataRow_Change);
..
..
..
private void DataRow_Change(object sender, DataRowChangeEventArgs e)
{
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");
}

All the best,
Phil.
 
I definitely see action with the code you gave me. Thank you very much.

However, I'm getting update error. One of the column in the dataset is a
primary key in the database. The update command is automatically generated
when I add the dbapater control to the form. It tries to update the primary
key columnas well.
Can you suggest how I can fix this problem? Thanks.

I'm gonna try to set that column in dataset to a primary key and see if that
would help.

Phil Williams said:
Hi,
You could try

dsVehicle.Tables[ "vehDetail" ].RowChanged +=
new DataRowChangeEventHandler(dataRow_Change);
.
.
.
private void DataRow_Change(object sender, DataRowChangeEventArgs e)
{
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");
}

All the best,
Phil.

Alpha said:
Hi, I have a datagrid and its source is a dataset. When I change information
on the grid does that automatically gets change in the dataset? If not then
how do I do that? I use the following update statement when the form is
closed to udpate the database but the changes are not there.
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");

Thanks, Alpha
 
I just open the dataset schema and it already has a primary key marked on the
correct column, VID. I don't understand why the dbadapter.Update command
would still try to update that.

Phil Williams said:
Hi,
You could try

dsVehicle.Tables[ "vehDetail" ].RowChanged +=
new DataRowChangeEventHandler(dataRow_Change);
.
.
.
private void DataRow_Change(object sender, DataRowChangeEventArgs e)
{
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");
}

All the best,
Phil.

Alpha said:
Hi, I have a datagrid and its source is a dataset. When I change information
on the grid does that automatically gets change in the dataset? If not then
how do I do that? I use the following update statement when the form is
closed to udpate the database but the changes are not there.
oleDbDataAdapter1.Update(dsVehicle, "vehDetail");

Thanks, Alpha
 
Back
Top