T
Tim Holgerson
Hi,
I am new to C# and to the .NET data environment. I am having some
trouble understanding some of the events around deleting rows.
Here is my problem:
I delete the row from a bound datagrid using a currency mananger:
CurrencyManager cm = (CurrencyManager)
this.dataGridEng.BindingContext[this.oEngClassObj.EngObjDataSet.Tables["EngClasses"]];
if ( !(cm.List is DataViewManager) && ( cm.Count >= 0 ) )
{
try
{
cm.RemoveAt( this.dataGridEng.CurrentRowIndex);
}
catch (Exception ew)
{
this.evParentExceptHandler(this,ew);
}
}
this seems to work and the row is deleted from the table, but it is
not deleted from the underlying SQL data table.
I trap the RowDeleting event on the table and throw an exception if
the row should not be deleted (has children, etc.) This too works
fine. So the to me it appears the cm.RemoveAt line triggers the
RowDeleting event on the DataTable. My problem seems to be that the
actual DataRow DataRowState is not flagged as Deleted, so when I call
the Update method of the DataAdapter nothing is sent to the SQL
server.
If I call the AcceptChanges() method of the DataTable right after the
cm.RemoveAt() I get an exception Cannot delete row not in table.
I know I am missing something simple here. Any help would be
appreciated.
Thanks
Tim Holgerson
I am new to C# and to the .NET data environment. I am having some
trouble understanding some of the events around deleting rows.
Here is my problem:
I delete the row from a bound datagrid using a currency mananger:
CurrencyManager cm = (CurrencyManager)
this.dataGridEng.BindingContext[this.oEngClassObj.EngObjDataSet.Tables["EngClasses"]];
if ( !(cm.List is DataViewManager) && ( cm.Count >= 0 ) )
{
try
{
cm.RemoveAt( this.dataGridEng.CurrentRowIndex);
}
catch (Exception ew)
{
this.evParentExceptHandler(this,ew);
}
}
this seems to work and the row is deleted from the table, but it is
not deleted from the underlying SQL data table.
I trap the RowDeleting event on the table and throw an exception if
the row should not be deleted (has children, etc.) This too works
fine. So the to me it appears the cm.RemoveAt line triggers the
RowDeleting event on the DataTable. My problem seems to be that the
actual DataRow DataRowState is not flagged as Deleted, so when I call
the Update method of the DataAdapter nothing is sent to the SQL
server.
If I call the AcceptChanges() method of the DataTable right after the
cm.RemoveAt() I get an exception Cannot delete row not in table.
I know I am missing something simple here. Any help would be
appreciated.
Thanks
Tim Holgerson