getting error code
-
I have to change some of my logic based on the error returned by a code. I have to first try to do a simple insert in a table. If it throws a error then i will have to change the statement(update) and again try the insert. How can i do this. Sorry if i hv posted the question in the wrong discussion board. It may be a quesiton of c# also
-
I have to change some of my logic based on the error returned by a code. I have to first try to do a simple insert in a table. If it throws a error then i will have to change the statement(update) and again try the insert. How can i do this. Sorry if i hv posted the question in the wrong discussion board. It may be a quesiton of c# also
I assume that you expect an error because the record already exists? Then do it the other way arond; first try the update and check how many records were updated. If the record didn't exist the number of records is zero, and you know that you have to make an insert instead. If you are using MS SQL Server, you can do this in a stored procedure:
create procedure DoSomeSetting
@SomeId int,
@SomeValue somedatatype
asupdate DaTable
set Something = @SomeValue
where SomeId = @SomeIdif @@rowcount = 0 begin
insert into DaTable (Something)
values (@SomeValue)end
--- b { font-weight: normal; }