OracleBulkCopy批量插入数据
时间:2021-07-01 10:21:17
帮助过:4人阅读
/// <summary>
2 /// 批量插入数据
3 /// </summary>
4 /// <param name="table">数据表</param>
5 /// <param name="targetTableName">数据库目标表名</param>
6 /// <returns></returns>
7 public static bool ExcuteBulkData(DataTable table,
string targetTableName)
8 {
9 bool result =
false;
10 using (ODAC.OracleConnection conn =
new ODAC.OracleConnection(connStr))
11 {
12 using (ODAC.OracleBulkCopy bulkCopy =
new ODAC.OracleBulkCopy(connStr, ODAC.OracleBulkCopyOptions.Default))
13 {
14 if (table !=
null && table.Rows.Count >
0)
15 {
16 bulkCopy.DestinationTableName =
targetTableName;
17 for (
int i =
0; i < table.Columns.Count; i++
)
18 {
19 string col=
table.Columns[i].ColumnName;
20 bulkCopy.ColumnMappings.Add(col, col);
21 }
22 conn.Open();
23 bulkCopy.WriteToServer(table);
24 result =
true;
25 }
26 }
27 }
28 return result;
29 }
Oracle批量插入
OracleBulkCopy批量插入数据
标签: