Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends
now i am writing code for using each insert method for all insert operation. like this i am writing for delete,update,search. this take lot of code for every operation. but I would like to use single insert method for different table with their parameters and also for update,delete,search method.please give me any sample code for my requirement.
Thank you
Posted
Comments
Abhijit Parab 3-Oct-12 2:14am    
your all tables contains same columns?
baskaran chellasamy 3-Oct-12 4:41am    
tables are different

1 solution

The easiest way is to write a stored procedure which does the job - it starts a transaction, does the inserts (or updates, or deletes) and commits if it all works.
SQL
CREATE PROCEDURE sp_InsertMultiple
    (
    @Text1 varchar(255),
    @Text2 varchar(255)
    )
AS
BEGIN
    BEGIN TRAN
    INSERT INTO Table1 (Column1) VALUES (@Text1)
    INSERT INTO Table2 (Column2) VALUES (@Text2)
    COMMIT TRAN
END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900