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].Value = "2"; rs.Fields[2].Value = ""; rs.Fields[3].Value = "11111111"; rs.Fields[4].Value = "0"; rs.Fields[5].Value = "打发打发dfadafdadafde"; rs.Fields[6].Value = ""; rs.Fields[7].Value = "2016/10/1 22:23:48"; rs.Fields[8].Value = 12; rs.Update(); } rs.Close(); cn.Close(); }
时间: 2024-12-27 23:13:21