delete rows from datagrid

S

Sam

Hi,
I'm doing the following :

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
dgDeleted.DataSource = dsDeleted

basically I create a dataset dsDeleted that gets all the rows deleted
in dsEquivalents, and I fill a datagrid dgDeleted with this dataset.
My problem is that whatever rows I delete, dgDeleted is always empty
and does not seem to get the deleted rows.

What should I do to store the deleted rows in a dataset so i can
proceed to further operations ?

Thx
 
P

Pipo

Hi Sam,

From the MSDN:
Gets a copy of the DataSet containing all changes made to it since it was
last loaded, or since AcceptChanges was called

Did you call Acceptchanges?
 
C

Cor Ligthert

Sam,

A datagrid does not show deleted row, and that change is not changed.

Maybe you can use the RejectChanges method on that extra dataset, that you
made with getchanges. (Know that new added rows which are deleted are not
seen as deleted however directly will removed with a delete).

I hope this helps,

Cor
 
S

Sam

thx
I've changed my code to this :

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
added line ---->dsEquivalents.AcceptChanges()
dgDeleted.DataSource = dsDeleted

but dgDeleted is still empty. I don't know why :(
 
P

Pipo

Sam,

Try:
added line ---->dsEquivalents.AcceptChanges()
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)
 
S

Sam

Cor,
This new added datagrid was just to see if my rows were properly marked
as deleted anyway. I do not intend to keep this datagrid.
But apparentely my deleted rows are NOT marked as deleted as I would
assume they would be added to this datagrid otherwise. Basically I want
my dsDeleted dataset to contain rows that are marked as deleted so that
I can call a stored procedure according to what is in this dataset.
Any idea what might go wrong ?

thx
 
P

Pipo

Sam,

Sorry I meant:

added line ---->dsEquivalents.AcceptChanges()
'Code wich deletes the records
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)

Also try this to see if there are changes:
If Not myDataSet.HasChanges(DataRowState.Deleted) Then Exit Sub

And if you are filling the dataset with records yourself (not database)
try also the AcceptChangesDuringFill = false property.
 
C

Cor Ligthert

Sam,

Did you try that

Dim dsDeleted As New DataSet
dsDeleted = dsEquivalents.GetChanges(DataRowState.Deleted)

dsDeleted.RejectChanges

dgDeleted.DataSource = dsDeleted

Cor
 
S

Sam

Pipo,
I've tried that.
Then dsDeleted' s value is 'Nothing', and doesn't contain any of the
deleted rows in dgEquivalents.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top