从数据库返回时无效的CAST

时间:2015-06-08 19:40:45

标签: c# asp.net asp.net-web-api asp.net-web-api2

我正在运行查询并从该查询返回结果集。除了来自AS400的客户编号数据类型之外,一切都很有效,无论我在模型中使用何种数据类型,它都无法进行CAST。我确信有一些简单的东西我不在,但是12个小时足够长。我可以验证as400中的客户编号字段是否为数字值但是我无法确定as400中的确切值类型。

这是我填写的列表。

while (reader.Read())
{
    //Lets add the data to our list we created earlier...
    customerList.Add(new getCustomerInfoModel
    {
        // What returned values do we want to list...
        UMENT = reader.GetString(0),
        UMCUS = reader.GetInt32(1),
        UMNAM = reader.GetString(2),
        UMSLC = reader.GetString(3)
    });
}

和我的模特......

public class getCustomerInfoModel
{
    public string UMENT { get; set; }
    public int UMCUS { get; set; }
    public string UMNAM { get; set; }
    public string UMSLC { get; set; }
}

1 个答案:

答案 0 :(得分:0)

正在使用错误的数据类型:

<?php
session_start();
$captchanumber = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz';
$captchanumber = substr(str_shuffle($captchanumber), 0, 5);
$_SESSION["code"]=$captchanumber;
$im = imagecreatetruecolor(50, 24);
$bg = imagecolorallocate($im, 22, 86, 165); //background color blue
$fg = imagecolorallocate($im, 255, 255, 255);//text color white
imagefill($im, 0, 0, $bg);
imagestring($im, 5,5,5,  $captchanumber, $fg);
header("Cache-Control: no-cache, must-revalidate");
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

这允许程序正确返回。

UMCUS = reader.GetDecimal(1)

<强>类别:

while (reader.Read())
{
    //Lets add the data to our list we created earlier...
    customerList.Add(new getCustomerInfoModel
    {
        // What returned values do we want to list...
        UMENT = reader.GetString(0),
        UMCUS = reader.GetDecimal(1),
        UMNAM = reader.GetString(2),
        UMSLC = reader.GetString(3)
    });
}