可以使用单个按钮将数据插入多个表吗? [英] Can a single button be used to insert data into multiple table?

查看:62
本文介绍了可以使用单个按钮将数据插入多个表吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在从事书店管理项目。我有5种不同类别的书和5种不同的表格。所以我有这个数据输入页面用数据文本框创建,下拉列表框用于选择类别/表格名称:

< tr>< td style =text-align:left; color:blue; font-size:30px; font-family:Maiandra GD> CATEGORY:< / td>< td> < asp:DropDownList ID =DropDownList1CssClass =txt2runat =server> 
< asp:ListItem> Academic&专业与LT; / ASP:的ListItem>
< asp:ListItem>儿童图书< / asp:ListItem>
< asp:ListItem> College Books< / asp:ListItem>
< asp:ListItem>入口书籍< / asp:ListItem>
< asp:ListItem>文献&小说< / ASP:的ListItem>
< / asp:DropDownList>< / td>< / tr>





所以我需要帮助如何使用单个按钮我可以插入多个表?该表应根据下拉列表框中的选择进行选择..

表名与listitem相同



假设我选择入口书籍,那么数据必须插入入口书籍表格。



这里是所有表格的通用表格结构 -

 name varchar(20)not null primary key,
aurthor varchar(20),
price int,
details varchar(1000)





谢谢

解决方案

将表名作为参数传递并使用您存储的这样的程序:

 创建 程序 InsertData 

@ tablename varchar 50

AS
BEGIN
- 检查条件

如果 @ tablename = ' Academic&专业'
BEGIN
- 表格的插入查询'Academic&专业'
END

if @ tablename = ' 儿童图书
BEGIN
- 火灾插入查询表'儿童图书'
结束


- 检查所有表格
END


您可以在按钮单击时执行存储过程或多组插入查询。

您可以将它们放入事务中以回滚任何相关插入。

I have been working on a bookstore management project. I have 5 different categories of book and 5 different tables for them.. So i have this data entry page created with textboxes for data and dropdown list-box for selecting the category/table name:

<tr><td style="text-align: left;color:blue; font-size:30px; font-family:Maiandra GD ">CATEGORY :</td><td> <asp:DropDownList ID="DropDownList1" CssClass="txt2" runat="server">
    <asp:ListItem>Academic & Professional</asp:ListItem>
    <asp:ListItem>Children Books</asp:ListItem>
    <asp:ListItem>College Books</asp:ListItem>
    <asp:ListItem>Entrance Books</asp:ListItem>
    <asp:ListItem>Literature & Fiction</asp:ListItem>
    </asp:DropDownList></td></tr>



So i need help as to how using a single button i can insert into multiple tables?? The table should be chosen as per the selection in the dropdownlistbox..
The table names are same as the listitem

Suppose i select Entrance books then the data must be inserted into the Entrance books table.

Here''s the common table structure for all the tables--

name varchar(20) not null primary key,
aurthor varchar(20),
price int,
details varchar(1000)



Thanks

解决方案

Pass table name as parameter and use your stored procedure like this:

Create Procedure InsertData
(
@tablename varchar(50)
)
AS
BEGIN
--Check Conditions

if @tablename = 'Academic & Professional'
BEGIN
--fire insert query for table 'Academic & Professional'
END

if @tablename = 'Children Books'
BEGIN
--fire insert query for table 'Children Books'
END


--check for all the tables
END


You can execute a stored procedure or multiple sets of insert queries on button click.
You can put them in a transaction to rollback any dependent inserts.


这篇关于可以使用单个按钮将数据插入多个表吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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