i am using visual web developer 2005 and SQL Express 2005 with VB as the code behind
i have a button and in the button click event i have written codes to INSERT to a database table - it has one primary key
so when i click the button, if there is already a row with primary key fields value as 10 and if i try to INSERT with the same value in the primary key field there will occur primary key constraint
so , if i try to INSERT with the already existing primary key fields value, instead of INSERTing it should be UPDATEd without generating any error
please help me
In ur SQl procedure
Include
If exists (select [PrimaryKeyColumn] from UrTable where PrimarKey = @.PrimaryKey)
Update ...
else
Insert ...
Like this u get to check for existing key , if exists it will execute an update else an insert
Hope that helps u
No comments:
Post a Comment