Insert if Update returns No record found

  • Thread starter mahesh rao via .NET 247
  • Start date
M

mahesh rao via .NET 247

I have a database which stores the Accounts and productsinformation. Account is always updated with products values. Forexisting products, I have to use UPDATE SQL command. If newproducts are added into Products table, the new Product rowsneed to be inserted into Accounts table.

Is there a way I can INSERT a record, if Update returnsNo-Record-found with minimum trips to database? I'm using Accessdatabase and CSharp.
 
V

Val Mazur \(MVP\)

Hi,

What you could do is to call stores procedure and inside of this stored
procedure first check if record exists using EXISTS function (I do not
remember exact syntax, but it should look like)

If EXISTS (SELECT .... WHERE .....)
UPDATE ...
ELSE
INSERT ....

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



I have a database which stores the Accounts and products information.
Account is always updated with products values. For existing products, I
have to use UPDATE SQL command. If new products are added into Products
table, the new Product rows need to be inserted into Accounts table.

Is there a way I can INSERT a record, if Update returns No-Record-found with
minimum trips to database? I'm using Access database and CSharp.
 

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