Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a form with one textbox and a gridview.
i am saving data from this form to two different tables (ServiceCategory, ServiceActivity)
ServiceCategory has two columns catid(pk) IDENTITY and category and
ServiceActivity has two columns catid(fk) and activity

when the save button is clicked the data is save to ServiceCategory before ServiceActivity
i used this sql statement but it is not working with ServiceActivity pls help me out

SQL
string sqlQuery = null;
            sqlQuery = "Insert into ServiceActivity values(Catid, Activity) SELECT Catid from ServiceCategory WHERE Category ='" + Category + "','" + Activity + "'";
Posted

here you can use store procedure instead of writing your command.
u can call that two stored procedure on that button_Click event so data will be saved in database at one button click.
 
Share this answer
 
While inserting data, you need to make sire number of columns being inserted is equal to the values. In your case, the two are not same.

Also, note that you can run an insert into one table at a time.
 
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