• SqlBulkCopy批量添加数据


    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();
  • 相关阅读:
    Daily Scrum 10.24
    Daily Srum 10.22
    TFS的使用
    Daily Srum 10.21
    Scrum Meeting 报告
    团队博客作业Week4 --- 学霸网站--NABC
    团队博客作业Week3 --- 项目选择&&需求疑问
    团队博客作业Week2 --- 学长学姐访谈录
    团队博客作业Week1 --- 团队成员简介
    js将数组中一个或多个字段相同的子元素中合并
  • 原文地址:https://www.cnblogs.com/jiangqw/p/4724555.html
Copyright © 2020-2023  润新知