DataSet / HasChanges / Delete Row

  • Thread starter Thread starter Raterus
  • Start date Start date
R

Raterus

Hi,

In my DataSet, I'm trying to keep track of row deletions, so later I can check HasChanges to see if I need to update the datasource. I'm trying to delete a specific row in the dataset that I search out from a primary key. I've found the DataRow I want to delete and have a reference to it.

I've tried this,
myDataSet.myTable.rows.remove(theRowIFound), but it appears this actually removes the row, and doesn't just change the rowstate (correct?)

The only way I see to delete a row/change rowstate is to have the actual ordinal of the row I'm after. How can I get this? Or is there an easier way I can delete this row and change the rowstate, using the actual reference to the row I have?

Thanks!
--Michael
 
I think this is correct, you delete the row from the table
then when you update the dataset it will be deleted from the database.

You can use row.RowState = DataRowState.Deleted
to check if the row is marked for deletion.



Hi,

In my DataSet, I'm trying to keep track of row deletions, so later I can check HasChanges to see if I need to update the datasource. I'm trying to delete a specific row in the dataset that I search out from a primary key. I've found the DataRow I want to delete and have a reference to it.

I've tried this,
myDataSet.myTable.rows.remove(theRowIFound), but it appears this actually removes the row, and doesn't just change the rowstate (correct?)

The only way I see to delete a row/change rowstate is to have the actual ordinal of the row I'm after. How can I get this? Or is there an easier way I can delete this row and change the rowstate, using the actual reference to the row I have?

Thanks!
--Michael
 
Hi,

Try row.Delete instead of row.Remove.
it should change the row state if row isn't Added (it will remove it if it
is added).

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Hi,

In my DataSet, I'm trying to keep track of row deletions, so later I can
check HasChanges to see if I need to update the datasource. I'm trying to
delete a specific row in the dataset that I search out from a primary key.
I've found the DataRow I want to delete and have a reference to it.

I've tried this,
myDataSet.myTable.rows.remove(theRowIFound), but it appears this actually
removes the row, and doesn't just change the rowstate (correct?)

The only way I see to delete a row/change rowstate is to have the actual
ordinal of the row I'm after. How can I get this? Or is there an easier
way I can delete this row and change the rowstate, using the actual
reference to the row I have?

Thanks!
--Michael
 
I guess I wasn't very clear, I tried that, but I don't know how to get the index of the row I'm deleting.
 
Raterus said:
I've tried this,
myDataSet.myTable.rows.remove(theRowIFound), but it appears
this actually removes the row, and doesn't just change the
rowstate (correct?)

Use theRowIFound.Delete;

This will mark the row as RowState = Deleted, but not remove it from the
Rows collection (as you correctly noted that .Remove() does).

--Mike
 
Huh?
Don't you have a reference to the row itself?
Why do you need an index?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

I guess I wasn't very clear, I tried that, but I don't know how to get the
index of the row I'm deleting.
 
Back
Top