日期:2014-05-16 浏览次数:20616 次
/// <summary>
/// Bulk方式插入
/// </summary>
/// <param name="dt"></param>
public void ExecuteSqlBulkCopy(DataTable dt)
{
using (SqlConnection conn = new SqlConnection(GetConnectionString))
{
SqlBulkCopy bulk = new SqlBulkCopy(conn);
bulk.DestinationTableName = "TestTable";
bulk.BatchSize = dt.Rows.Count;
if (dt != null && dt.Rows.Count != 0)
{
conn.Open();
bulk.WriteToServer(dt);
}
bulk.Close();
}
}