I have a datagrid view which shows table data from a database
Environment: - C# 4.0 - SQL Server 2005 - Visual studio 2010
What i want is: On a row to row basis automatically save changes. So when I edit the first row and then leave the row. It should save the changes to the database.
I've used this code:
In the From1 Load:
dataSet1.TblObject.RowChanged += rowUpdate;
The eventhandler:
private void rowUpdate(object sender, DataRowChangeEventArgs e)
{
DataRow dr = e.Row;
if (dr.RowState == DataRowState.Modified)
{
tblObjectTableAdapter.Update(dr);
}
}
When I've edited a row in the grid, tblObjectTableAdapter.Update(dr);
is called the data is stored to the table. Which is good. But the event keeps on triggering as if it's called recursively. So the tblObjectTableAdapter.Update(dr);
is causing a dataSet1.TblObject.RowChanged
event. But I can't differentiate between the both of them. I'm guessing I'm using the wrong event to store my values but I can't find any event that sounds logical to me. What am I doing wrong?
I've made a dataset xsd:
I've picked the dataset as datasource in this gridview: