C# 为什么在iis下运行的asp.net网站中出现这种奇怪的sqlbulkcopy行为?
我正在使用C# 为什么在iis下运行的asp.net网站中出现这种奇怪的sqlbulkcopy行为?,c#,asp.net,iis,sqlbulkcopy,C#,Asp.net,Iis,Sqlbulkcopy,我正在使用SqlClient.SqlBulkCopy尝试将csv文件批量复制到 数据库在调用 ..WriteToServer方法 “字符串类型的给定值来自 无法将数据源转换为 输入指定目标的十进制数 专栏。” 这是我的密码 dt.Columns.Add("IsDeleted", typeof(byte)); dt.Columns.Add(new DataColumn("CreatedDate", typeof(DateTime))); foreach (DataRow dr i
SqlClient.SqlBulkCopy
尝试将csv文件批量复制到
数据库在调用
..WriteToServer方法
“字符串类型的给定值来自
无法将数据源转换为
输入指定目标的十进制数
专栏。”
这是我的密码
dt.Columns.Add("IsDeleted", typeof(byte));
dt.Columns.Add(new DataColumn("CreatedDate", typeof(DateTime)));
foreach (DataRow dr in dt.Rows)
{
if (dr["MobileNo2"] == "" && dr["DriverName2"] == "")
{
dr["MobileNo2"] = null;
dr["DriverName2"] = "";
}
dr["IsDeleted"] = Convert.ToByte(0);
dr["CreatedDate"] = Convert.ToDateTime(System.DateTime.Now.ToString());
}
string connectionString = System.Configuration.ConfigurationManager.
ConnectionStrings["connectionString"].ConnectionString;
SqlBulkCopy sbc = new SqlBulkCopy(connectionString);
sbc.DestinationTableName = "DailySchedule";
sbc.ColumnMappings.Add("WirelessId", "WirelessId");
sbc.ColumnMappings.Add("RegNo", "RegNo");
sbc.ColumnMappings.Add("DriverName1", "DriverName1");
sbc.ColumnMappings.Add("MobileNo1", "MobileNo1");
sbc.ColumnMappings.Add("DriverName2", "DriverName2");
sbc.ColumnMappings.Add("MobileNo2", "MobileNo2");
sbc.ColumnMappings.Add("IsDeleted", "IsDeleted");
sbc.ColumnMappings.Add("CreatedDate", "CreatedDate");
sbc.WriteToServer(dt);
sbc.Close();
在visual studio Development server下运行时没有错误,但在iis下运行时会出现错误
这是我的sql server表详细信息
[Id] [int] IDENTITY(1,1) NOT NULL,
[WirelessId] [int] NULL,
[RegNo] [nvarchar](50) NULL,
[DriverName1] [nvarchar](50) NULL,
[MobileNo1] [numeric](18, 0) NULL,
[DriverName2] [nvarchar](50) NULL,
[MobileNo2] [numeric](18, 0) NULL,
[IsDeleted] [tinyint] NULL,
[CreatedDate] [datetime] NULL,
你能提供样本数据吗
听起来像是手机号码之一。Id首先隔离确切的列,然后检查源数据。另外,听起来DataTable都是字符串值,请尝试键入数据集。如果我不得不猜测-文化。IIS使用的是什么文化,您的桌面应用程序使用的是什么文化?逗号vs句号等等。@Marc刚刚发现文化是问题所在。。。。。你刚才发表了一个有价值的评论。。。