码迷,mamicode.com
首页 > 数据库 > 详细

SqlBulkCopy批量添加数据

时间:2015-08-12 16:41:12      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

var sqlconn = ConfigurationManager.ConnectionStrings["SQLConnStringRead"].ConnectionString;
            string sql = "select * from TicketRecord where 1=2";
            //Database db = new Database(sqlconn);
            //var ds = db.QueryExtend(sql);

            DataTable ImportDT = SqlHelper.ExecuteDataTable(SqlHelper.SQLConnStringRead, CommandType.Text, sql);
            for (int i = 1; i <= count; i++)
            {
                DataRow dr = ImportDT.NewRow();
                var tn = "SK".PadRight(8 - i.ToString().Length, 0) + i;
                dr["TicketNumber"] = tn;
                dr["SceneryId"] = 0;
                dr["SceneryName"] = "";
                dr["EnterpriseId"] = 0;
                dr["EnterpriseName"] = "";
                dr["BatchNumber"] = "";
                dr["SerialId"] = "";
                dr["ParentId"] = 0;
                dr["TicketClassId"] = 0;
                dr["TicketClassName"] = "";
                dr["TicketTypeId"] = 0;
                dr["TicketTypeName"] = "";
                dr["RetailPrice"] = 0;
                dr["Discount"] = 0;
                dr["PeopleCount"] = 0;
                dr["TotalAmount"] = 0;
                dr["RefundPackageNum"] = 0;
                dr["RefundNum"] = 0;
                dr["RefundAmount"] = 0;

                dr["FreePersonCount"] = 0;
                dr["ValidStartTime"] = "2015-08-12";
                dr["ValidEndTime"] = "2015-08-12";
                dr["SaleDate"] = "2015-08-12";
                dr["UseNumber"] = 0;
                dr["HasCheckedNum"] = 0;
                dr["PayType"] = 0;
                dr["PayStatus"] = 0;
                dr["TicketStatus"] = 0;
                dr["DrawWay"] = 0;
                dr["PrintType"] = 0;
                dr["PackageNum"] = 0;
                dr["HostName"] = "";
                dr["RowStatus"] = 0;
                dr["CreatorId"] = 0;
                dr["CreateBy"] = "";
                dr["CreateOn"] = "2015-08-12";
                dr["UpdateId"] = 0;
                dr["UpdateBy"] = "";
                dr["UpdateOn"] = "2015-08-12";
                dr["Prefix"] = "";
                dr["Postfix"] = "";
                dr["MidNum"] = "";
                dr["Remark"] = "";
                dr["BookMobile"] = "";
                dr["ActivateDate"] = "2015-08-12";
                dr["InsidePrice"] = 0;

                ImportDT.Rows.Add(dr);
            }
            SqlConnectionStringBuilder sqlcsb = new SqlConnectionStringBuilder();
            sqlcsb.ConnectionString = ConfigurationManager.ConnectionStrings["SQLConnStringRead"].ConnectionString;
            SqlConnection SqlConn = new SqlConnection(sqlcsb.ConnectionString);
            SqlConn.Open();
            SqlBulkCopy bulkCopy = new SqlBulkCopy(SqlConn); ;
            bulkCopy.BatchSize = count;
            bulkCopy.BulkCopyTimeout = 500000000;
            bulkCopy.DestinationTableName = "TicketRecord";
            bulkCopy.WriteToServer(ImportDT);
            bulkCopy.Close();
            SqlConn.Close();

 

SqlBulkCopy批量添加数据

标签:

原文地址:http://www.cnblogs.com/jaday/p/4724555.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!