C# 构造一次插入多条数据的SQL语句 no

View Code
 1 StringBuilder sb = new StringBuilder();
2 if (arrService.Length > 0)
3 {
4 for (int i = 0; i < arrService.Length; i++)
5 {
6 if (string.IsNullOrEmpty(sb.ToString()))
7 {
8 sb.AppendFormat("INSERT INTO [SM_PackageEntry] select '{0}','{1}','{2}' ", servicePackageID, arrService[i][0], arrService[i][1]);
9 }
10 else
11 {
12 sb.AppendFormat(" UNION ALL select '{0}','{1}','{2}'", servicePackageID, arrService[i][0], arrService[i][1]);
13 }
14 }
15 //执行SQL
16 SqlHelper.ExecuteSql(sb.ToString());
17 sb.Clear();//清空SQL
18 }

原文地址:https://www.cnblogs.com/252e/p/2168329.html