首页 > 数据库技术 > 详细

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

时间:2016-10-02 06:44:11      阅读:902      评论:0      收藏:0      [点我收藏+]
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();


            

        }

 

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

原文:http://www.cnblogs.com/volts0302/p/5926699.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!