首页 > 代码库 > C# 调用Adodb对Access数据库执行批量插入

C# 调用Adodb对Access数据库执行批量插入

public void BatchInsertIntoAccess(DataTable dt)        {            ADODB.Connection cn;            ADODB.Recordset rs;            string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\FileTmp\MMSCRM.mdb;Persist Security Info=False";            cn = new ADODB.Connection();            cn.ConnectionString = strConn;            //打开数据库            try            {                //cn.Open(strConn, "sa", "password", -1);                cn.Open(strConn);            }            catch (Exception ex)            {                throw new Exception(ex.Message);            }            finally            {                Console.WriteLine(cn.State);            }            //打开记录集            rs = new ADODB.Recordset();            rs.LockType = ADODB.LockTypeEnum.adLockPessimistic;            rs.CursorType = ADODB.CursorTypeEnum.adOpenDynamic;            rs.Open("MSG_Outbox",cn);            //如果记录集为空,输出一个错误信息            for (int i = 0; i < 10;i++ )            {                rs.MoveLast();                object missing = System.Reflection.Missing.Value;                rs.AddNew(missing, missing);                //第0列为自增列,忽略                rs.Fields[1].Valuehttp://www.mamicode.com/= "http://www.mamicode.com/2";                rs.Fields[2].Valuehttp://www.mamicode.com/= "";                rs.Fields[3].Valuehttp://www.mamicode.com/= "11111111";                rs.Fields[4].Valuehttp://www.mamicode.com/= "0";                rs.Fields[5].Valuehttp://www.mamicode.com/= "打发打发dfadafdadafde";                rs.Fields[6].Valuehttp://www.mamicode.com/= "";                rs.Fields[7].Valuehttp://www.mamicode.com/= "2016/10/1 22:23:48";                rs.Fields[8].Value = http://www.mamicode.com/12;>

 

C# 调用Adodb对Access数据库执行批量插入