本文介绍了OracleBulkCopy不会在表中插入条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我正在执行的代码:
Here's the code I'm executing:
public static void Main(string[] args)
{
var connectionString = "Data Source=dbname;User Id=usrname;Password=pass;";
DataTable dt = new DataTable("BULK_INSERT_TEST");
dt.Columns.Add("N", typeof(double));
var row = dt.NewRow();
row["N"] = 1;
using (var connection = new OracleConnection(connectionString)){
connection.Open();
using(var bulkCopy = new OracleBulkCopy(connection, OracleBulkCopyOptions.UseInternalTransaction))
{
bulkCopy.DestinationTableName = dt.TableName;
bulkCopy.WriteToServer(dt);
}
}
using (var connection = new OracleConnection(connectionString)){
connection.Open();
var command = new OracleCommand("select count(*) from BULK_INSERT_TEST", connection);
var res = command.ExecuteScalar();
Console.WriteLine(res); // Here I'm getting 0
}
}
它使用OracleBulkCopy
在表中插入1个条目,然后对表中的行进行计数.为什么会出现0
行?这是表格的结构:
It uses OracleBulkCopy
to insert 1 entry to table and then it counts rows in the table.Why am I getting 0
rows? Here's the structure of table:
-- Create table
create table BULK_INSERT_TEST
(
n NUMBER
)
推荐答案
您实际上尚未将行添加到表中.您已经使用该表创建了具有正确列的新行,但实际上并未将其添加到表中.您需要:
You haven't actually added the row to the table. You've used the table to create a new row with the right columns, but not actually added it to the table. You need:
dt.Rows.Add(row);
(基本上在您的第一个using
语句之前)
(before your first using
statement, basically)
这篇关于OracleBulkCopy不会在表中插入条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!