一次插入多行 [英] insert multiple row at once

查看:105
本文介绍了一次插入多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,该表具有2列(类别和活动),我想创建一个C#表单
它将向表中插入行数据.您可以在类别下插入美容师",活动将是理发,美发师,修指甲"

我只是不知道如何开始.请帮助我

i have a table that have 2 columns (category and activity) i want to creat a c# form
that will insert rows data into the table. that is under category you can insert "Beautician" and the activity will be "barber, hair dresser, manicure"

i just dont know how to start. pls help me out

推荐答案

其中的实际SQL部分将通过UNION ALL运算符在要插入到一条语句中的每一行之间工作,如下所示:

The actual SQL part of this would work via a UNION ALL operator between each line to be inserted in the one statement like so:

INSERT INTO myTable(category, activity)
SELECT 'Beautician', 'barber'
UNION ALL
SELECT 'Beautician', 'hair dresser'
UNION ALL
SELECT 'Beautician', 'manicure'



您只需要在C#代码中构建此语句,然后对数据库调用一次即可.该特定语句将在myTable表中插入三行.



You would just need to build this statement in your C# code and then call it once against the database. This particular statement would insert three rows into the myTable table.


这篇关于一次插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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