那是我的代码:
protected void SendToServer_Click(object sender, EventArgs e)
{
DataTable Values = Session["valuesdt"] as DataTable;
if (Values.Rows.Count > 0)
{
//Fix up default values
for (int i = 0; i < Values.Rows.Count; i++)
{
Values.Rows[i]["Mobile1"] = Values.Rows[i]["Mobile1"].ToString() == "" ? 0 : double.Parse(Values.Rows[i]["Mobile1"].ToString());
Values.Rows[i]["Mobile2"] = Values.Rows[i]["Mobile2"].ToString() == "" ? 0 : double.Parse(Values.Rows[i]["Mobile2"].ToString());
Values.Rows[i]["Tel"] = Values.Rows[i]["Tel"].ToString() == "" ? 0 : double.Parse(Values.Rows[i]["Tel"].ToString());
Values.Rows[i]["Category"] = Values.Rows[i]["Category"].ToString();
}
DataTable dv = Values.DefaultView.ToTable(true, "Mobile1", "Mobile2", "Tel", "Category");
BulckCopyDataTable(dv, "client", 1000);
}
}
public void BulckCopyDataTable(DataTable dt,string DestinationTable,int batchSize)
{
connection.Open();
using (SqlBulkCopy copy = new SqlBulkCopy(connection))
{
copy.BatchSize = batchSize;
copy.DestinationTableName = DestinationTable;
copy.WriteToServer(dt);
connection.Close();
}
}
我不知道为什么会在数据库中引发此错误:
Mobile1 bigint, Mobile2 bigint, Tel bigint, Category nvarchar(MAX)