保存到多个表中 [英] save into multiple table

查看:61
本文介绍了保存到多个表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一个文本框和一个gridview的表单.
我正在将数据从此表单保存到两个不同的表(ServiceCategory,ServiceActivity)
ServiceCategory有两列catid(pk)IDENTITY和category和
ServiceActivity有两列catid(fk)和activity

单击保存按钮后,数据将在ServiceActivity之前保存到ServiceCategory
我使用了此sql语句,但不适用于ServiceActivity,请帮帮我

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

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

推荐答案

,您可以在其中使用存储过程而不是编写您的命令.
您可以在该button_Click事件上调用该两个存储过程,以便单击一次按钮即可将数据保存在数据库中.
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.


在插入数据时,您需要使要插入的全部列数相等值.就您而言,两者并不相同.

另外,请注意,您可以一次在一个表中运行插入.
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.


这篇关于保存到多个表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆