3

SqlClient.SqlBulkCopycsvファイルをデータベースに一括コピーするために使用しています。..WriteToServerメソッドを呼び出した後、次のエラーが発生します。

「データソースからのString型の指定された値は、指定されたターゲット列の10進数型に変換できません。」

これが私のコードです、

 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開発サーバーで実行している場合はエラーは発生しませんが、IISで実行している場合はエラーが発生します。

これが私のSQLサーバーテーブルの詳細です。

[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,
4

2 に答える 2

2

Can you provide sample data?

Sounds like it's one of the mobile numbers. Id start with isolating the exact column then checking the source data. Also, it sounds like the DataTable is all string values, try typing the dataset.

于 2010-05-30T11:48:52.597 に答える
2

If I had to guess - culture. What culture is IIS using, and what culture is your desktop app using? commas vs periods etc.

于 2010-05-30T20:44:37.763 に答える