this.BindingContext[this.objKPMGdonnées, "MyTable"].EndCurrentEdit();
foreach (MyDataSet.MyTableRow MyTableRow in objMyDataSet.MyTable)
{
try
{
switch (MyTableRow.RowState)
{
case DataRowState.Modified:
this.MyTableTableAdapter.Update(MyTableRow);
break;
case DataRowState.Added:
this.MyTableTableAdapter.Insert(
System.Convert.ToInt32(this.lblID.Text)
, MyTableRow.Libelle
);
break;
case DataRowState.Deleted:
int ID = System.Convert.ToInt32(MyTableRow["ID", DataRowVersion.Original]);
this.MyTableTableAdapter.Delete(ID);
break;
}
}
catch (Exception exp)
{
continue;
}
}
An other interesting thing on Delete case, to retrieve the ID of the row to delete, you must use DataRowVersion.Original, because there is two Dataset, the original one and the modified one.
Aucun commentaire:
Enregistrer un commentaire