Preferred way to do "update row, or insert if it doesn't exist" using TableAdapters in dataset desig

  • Thread starter Thread starter H5N1
  • Start date Start date
H

H5N1

hi there

the topic says it all.

I have a outer join select statement in tableadapter that populates
GridView, I want to make it updatetable, so I need to provide an update
command for table adapter.
the problem is that not all rows in gridview exist in database (since
it's an outer join) so I want to UPDATE statement to insert the row if
it doesn't exist.

What's the best practice?

thanks
 
The Sql "Pattern" for this would be (pseudocode)

IF NOT EXISTS( SELECT PrimaryKey from table where primaryKey=@primarykey)
BEGIN
INSERT INTO TABLE ---etf
END
ELSE
BEGIN
UPDATE TABLE SET .... etc
END
 

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

Back
Top