您好:
C# 如何把Dataset中的数据批量插入到ACCESS中?现在Dataset中大约有10万条记录,我用事务处理的办法,现在能达到每秒300条,请问怎么能够更快的插入?,我的代码如下:
int i = dsSyncData.Tables["JKData"].Rows.Count;
if (i > 0)
{
strPhone = dsSyncData.Tables["JKData"].Rows[0]["电话号码"].ToString();
OleDbConnection myConn = new OleDbConnection(strConnect_Data);
if (myConn.State != ConnectionState.Open)
myConn.Open();
OleDbDataAdapter myAdapter = new OleDbDataAdapter();
OleDbCommand myCommand = new OleDbCommand("Insert into devjkdata (更新时间,电话号码) values (@更新时间,@电话号码)", myConn);
myCommand.CommandType = CommandType.Text;
OleDbTransaction Trans = null;
Trans = myConn.BeginTransaction();
myCommand.Transaction = Trans;
//myCommand.Parameters.Add("@更新时间", OleDbType.Char, 19);
myCommand.Parameters.Add("@更新时间", "更新时间");
myCommand.Parameters["@更新时间"].SourceColumn = dsSyncData.Tables["JKData"].Columns["更新时间"].ColumnName;
//myCommand.Parameters.Add("@电话号码", OleDbType.Char, 11);
myCommand.Parameters.Add("@电话号码", "电话号码");
myCommand.Parameters["@电话号码"].SourceColumn = dsSyncData.Tables["JKData"].Columns["电话号码"].ColumnName;
//OleDbTransaction Trans = null;
//Trans = myConn.BeginTransaction();
//myCommand.Transaction = Trans;
for (int j = 0; j < i; j++)
{
myCommand.Parameters["@更新时间"].Value = dsSyncData.Tables["JKData"].Rows[j]["更新时间"];
myCommand.Parameters["@电话号码"].Value = dsSyncData.Tables["JKData"].Rows[j]["电话号码"];
myCommand.ExecuteNonQuery();
}
Trans.Commit();
Trans.Dispose();
}