The rows aren't deleted

  • Thread starter Thread starter yoramo
  • Start date Start date
Y

yoramo

Hello
I'm trying to delete a row from a dataset with the following code:

public void Update()
{
oleDbDataAdapter3.Update(dataSetGen11) ;
}
public void Delete(int iIndx)
{
dataSetGen11.Tables["Stam"].Rows.RemoveAt(iIndx) ;
Update() ;
dataSetGen11.Tables["Stam"].AcceptChanges() ;
}

the rows disappears from the datagrid but are still in the database (MS
Access).

what am I doing wrong?

Yoramo
 
Hi yoramo,

You are removing rows from collection instead of deleting them.
You should mark row as deleted with
dataSetGen11.Tables["Stam"].Rows[iIndx].Delete().

In this mode rows is still in collection and thus adapter will know how to
handle it - delete it in database.
 
Yoramo,
You are removing the rows from the dataset with this code so there is
nothing about these rows to synchronize back to the database. Use Delete on
the row instead so that it will be marked as deleted but still in the
dataset. Also you don't need to call AcceptChages on the table after
calling Update as it is called automatically by the Update method.
I'd suggest you get a copy of "ADO.NET Core Reference" by David Sceppa
as it has a good explanation and examples of working with data using both C#
and VB.NET.

Ron Allen
 
thanks it worked.


Miha Markic said:
Hi yoramo,

You are removing rows from collection instead of deleting them.
You should mark row as deleted with
dataSetGen11.Tables["Stam"].Rows[iIndx].Delete().

In this mode rows is still in collection and thus adapter will know how to
handle it - delete it in database.

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

yoramo said:
Hello
I'm trying to delete a row from a dataset with the following code:

public void Update()
{
oleDbDataAdapter3.Update(dataSetGen11) ;
}
public void Delete(int iIndx)
{
dataSetGen11.Tables["Stam"].Rows.RemoveAt(iIndx) ;
Update() ;
dataSetGen11.Tables["Stam"].AcceptChanges() ;
}

the rows disappears from the datagrid but are still in the database (MS
Access).

what am I doing wrong?

Yoramo
 
thanks. I will read more on ADO.NET (i do not have the mentioned book.).

Ron Allen said:
Yoramo,
You are removing the rows from the dataset with this code so there is
nothing about these rows to synchronize back to the database. Use Delete on
the row instead so that it will be marked as deleted but still in the
dataset. Also you don't need to call AcceptChages on the table after
calling Update as it is called automatically by the Update method.
I'd suggest you get a copy of "ADO.NET Core Reference" by David Sceppa
as it has a good explanation and examples of working with data using both C#
and VB.NET.

Ron Allen
yoramo said:
Hello
I'm trying to delete a row from a dataset with the following code:

public void Update()
{
oleDbDataAdapter3.Update(dataSetGen11) ;
}
public void Delete(int iIndx)
{
dataSetGen11.Tables["Stam"].Rows.RemoveAt(iIndx) ;
Update() ;
dataSetGen11.Tables["Stam"].AcceptChanges() ;
}

the rows disappears from the datagrid but are still in the database (MS
Access).

what am I doing wrong?

Yoramo
 
Back
Top