C# - 不能在AS400 DB2中插入十进制数

时间:2015-12-04 16:11:28

标签: c# db2 ibm-midrange

我正在尝试使用C#程序来推送DB2数据库中的数据。它适用于除DECIMAL(3,3)之外的所有字段,因此值介于0到1之间。我正在读取Excel文件,当值为0.144时,我在数据库中看到0.001。如果值为0.244,则为0.002。

我使用的是Oledb适配器。

OleDbCommand command = new OleDbCommand(commandLine, connection);
for (int i = 2; i <= worksheet.UsedRange.Rows.Count; i++)
{
    command = new OleDbCommand(commandLine, connection);
    // Here, you set your parameters for a single row
    command.Parameters.AddWithValue("R2CUS", Convert.ToString(worksheet.Cells[i, 1].Value));
    command.Parameters.AddWithValue("R2LOC", worksheet.Cells[i, 1].Value != null ? Convert.ToString(worksheet.Cells[i, 2].Value) : "");
    command.Parameters.AddWithValue("R2CATG", Convert.ToString(worksheet.Cells[i, 3].Value));
    command.Parameters.AddWithValue("R2CLAS", Convert.ToString(worksheet.Cells[i, 4].Value));
    command.Parameters.AddWithValue("R2DESC", Regex.Replace(Convert.ToString(worksheet.Cells[i, 5].Value), "[^\u0000-\u007F]", " "));
    command.Parameters.AddWithValue("R2MNRT", Convert.ToString(worksheet.Cells[i, 6].Value));
    command.Parameters.AddWithValue("R2DYRT", Convert.ToString(worksheet.Cells[i, 7].Value));
    command.Parameters.AddWithValue("R2WKRT", Convert.ToString(worksheet.Cells[i, 8].Value));
    command.Parameters.AddWithValue("R2MORT", Convert.ToString(worksheet.Cells[i, 9].Value));
    command.Parameters.AddWithValue("R2DSCP", Convert.ToString(worksheet.Cells[i, 10].Value));
    **command.Parameters.AddWithValue("R2DWP", Convert.ToString(worksheet.Cells[i, 11].Value));**
    command.Parameters.AddWithValue("R2CXCB", Convert.ToString(worksheet.Cells[i, 12].Value));
    command.Parameters.AddWithValue("R2CXRT", Convert.ToString(worksheet.Cells[i, 13].Value));
    command.Parameters.AddWithValue("R2STDT", Convert.ToString(worksheet.Cells[i, 14].Value));
    command.Parameters.AddWithValue("R2ENDT", Convert.ToString(worksheet.Cells[i, 15].Value));
    cptRow += command.ExecuteNonQuery();

    pg2.Value = i * 100 / worksheet.UsedRange.Rows.Count;
}
pg2.Value = 100;

0 个答案:

没有答案