using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

namespace confirmBeiZhu
{
class Program
{
static void Main(string[] args)
{
fabu();
}

protected static void fabu()
{
DateTime time1 = DateTime.Now;
string connectionString = "Max Pool Size=100000; Data Source=localhost;Initial Catalog=collection40;User ID=sa;Password=ccc";
SqlBulkCopy sqlbulkcopy = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.UseInternalTransaction);
sqlbulkcopy.DestinationTableName = "xyAddress";//数据库中的表名

SqlConnection sqlconnection = new SqlConnection(connectionString);
SqlDataAdapter sqldataadapter = new SqlDataAdapter("select * from xyAddress where 1=2", sqlconnection);
DataSet dataset = new DataSet();
sqldataadapter.Fill(dataset, "xyAddress");
DataTable datatable = dataset.Tables[0];
//生成20000条记录

//INSERT INTO [XyAddress] ([], [], [], [], [], [], [], [], [], []) VALUES ('', '', '', '', '', '', '', '', '', '')
for (int i = 0; i < 2; i++)
{
DataRow dr = datatable.NewRow();
dr["relation"] = "本人";
dr["xm"] = "张三" + i.ToString();
dr["leixing"] = "你好类型";
dr["dizhi"] = "你好2123" + i.ToString();
dr["hide"] = "0";
datatable.Rows.Add(dr);
}

sqlbulkcopy.WriteToServer(dataset.Tables[0]);

if (null != sqlconnection)
{
if (sqlconnection.State == ConnectionState.Open)
{
sqlconnection.Close();
sqlconnection.Dispose();
}
sqlconnection.Dispose();
}

DateTime time2 = DateTime.Now;
TimeSpan ts = time2 - time1;

Console.WriteLine("已处理完毕" + ts.TotalSeconds.ToString());

Console.ReadLine();
}


}
}

posted on 2017-06-07 17:23  御不凡  阅读(1104)  评论(0编辑  收藏  举报