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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
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..

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.