tableadatper update selected rows C#

Hi experts,

I have a typed dataset and a table pulled from sql database.

This table is presented on a grid on the interface where the user can interact (add/delete/update rows). At run time, i add a few rows programmatically (say these rows have a name that starts with "donotinsert - " in the name column) to this table that is meant for run-time only. I do not want these rows to be saved back to the database. The problem arises when a user deletes a row in the grid (i've checked the rowstate to be "deleted") and i do a tableadapter.update("name not like 'donotinsert -%'"), the deleted row in the grid does not get deleted in the sql table. If I however just use a straight tableadapter.update(table), then everything works as expected, but those "donotinsert - " rows will get added to the sql table.

How do i get around this??
Who is Participating?
Pawan KumarDatabase ExpertCommented:
This way it will not work. You have to define some custom logic for that.

Best way is to create a loop in your code and call a SP inside that.

SP will accept the 1 row at a time with operation type ...
IF  operation type ... = INSERT --> row will be inserted
IF  operation type ... = Update --> row will be updated
IF  operation type ... = Delete --> row will be deleted..
Dustin SaundersDirector of OperationsCommented:
Well, the issue is that you are updating from select results prior to the initial update.

I don't really use TableAdapters but technically it should work if you do both in this order:
tableadapter.update("name not like 'donotinsert -%'"));

Open in new window

That doesn't seem like an ideal way to handle, but if you have more detail on the control they are using to interact there's surely a more elegant solution.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.