为什么在i.net下运行的asp.net网站上sqlbulkcopy的这种奇怪行为?

时间:2010-05-30 09:40:12

标签: c# asp.net iis sqlbulkcopy

我正在使用SqlClient.SqlBulkCopy尝试将csv文件批量复制到 数据库。调用后我收到以下错误 ..WriteToServer方法。

  

“来自的String类型的给定值   数据源无法转换为   输入指定目标的十进制数   列“。

这是我的代码,

 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 developpement服务器下运行时没有错误,但在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,

2 个答案:

答案 0 :(得分:2)

您能提供样本数据吗?

听起来像是手机号码之一。 Id首先隔离精确列然后检查源数据。此外,它听起来像DataTable是所有字符串值,尝试键入数据集。

答案 1 :(得分:2)

如果我不得不猜 - 文化。 IIS使用什么文化,您的桌面应用程序使用什么文化?逗号与句号等。

相关问题