考虑我动态生成的数据表包含以下文件Id,Name,Mob1,Mob2
如果我的数据表有这个它会成功插入,
Id Name Mob1 Mob2
1 acp 9994564564 9568848526
但是当它是这样的时候,它会失败地说,
Id Name Mob1 Mob2
1 acp 9994564564
The given value of type String from the data source cannot be converted to type decimal of the specified target column.
我通过读取一个 csv 文件来生成我的数据表,
CSVReader reader = new CSVReader(CSVFile.PostedFile.InputStream);
string[] headers = reader.GetCSVLine();
DataTable dt = new DataTable();
foreach (string strHeader in headers)
{
dt.Columns.Add(strHeader);
}
string[] data;
while ((data = reader.GetCSVLine()) != null)
{
dt.Rows.Add(data);
}
任何建议如何在 C# 中的 BulkCopy 期间为数字字段插入空值...
编辑:
我试过这个dt.Columns["Mob2"].AllowDBNull = true;
,但它似乎不起作用......