我在一程序中运行后出现如下提示:the conversion of the varchar value '5030400100' overflowed an int cloum. maximum integer value exceeded.
请问大家有不有碰到过这样的情况,我定义的是string变量,难道长度不够?急死了,请大家指教 !

解决方案 »

  1.   

    int为四个字节,其值的范围:-2^31 (-2,147,483,648)-2^31 - 1 (2,147,483,647)
    你的程序出错就是因为'5030400100'所代表的整型超界。你的程序异常也很清楚的告诉你了,呵呵,建议你多学点英语。
      

  2.   

    以下是代码:程序是从一个EXCEL表中找出货品代号,然后根据货品代号到SQLSERVER中的UP—DEF表上查找价格,可这在这中间出现了上面的错误提示,程序停在了打*号的那一行。奇怪的是,那个代号在EXCEL表中还没有!请哪位给看一下!
    while not datamodule2.bh1Query.Eof do
    begin
    n:=datamodule2.bh1Query.Fields[0].AsString;
    datamodule2.bhquery.Close;
    datamodule2.bhquery.SQL.Clear;
    datamodule2.bhquery.SQL.Text:='select distinct 货品代号,货品规格 from [table2$]where 编号='+n+'';
    datamodule2.bhquery.Active:=true;
    bh:=datamodule2.bhquery.Fields[0].Asstring; 
    if bh='' then
    begin
    z:=1;
    showmessage('编号‘+n+‘没有找到货品代号!’);
    datamodule2.bh1query.Next;
    end
    else
    bh:=datamodule2.bhquery.Fields[0].Asstring; //货品代号gg:=datamodule2.bhquery.Fields[1].Asstring;//根据货品代号从UP—DEF表中找价格
    datamodule2.pricequery.Close;
    datamodule2.pricequery.SQL.Clear;
    datamodule2.pricequery.SQL.Text:='select up from UP_DEF where prd_no='+bh+'';
    datamodule2.pricequery.Active:=True;
    price:=datamodule2.pricequery.fields[0].asstring;*********
    if price='' then
    begin
    z:=1;
    listbox1.Items.Add(bh+' ['+gg+']');
    q:=q+1;
    showmessage('货品代号为'+bh+’没有找到价格‘);
    datamodule2.bh1query.Next;
    end
    else
    price:=datamodule2.pricequery.fields[0].asstring;   //UP_BEF表中的价格datamodule2.bh1Query.Next;
    end;
      

  3.   

    问题总算找出来了,是数据库中的价格表的问题,但还是不明白为什么会这样报错。还有请问以下两个有区别吗?
    datamodule2.pricequery.SQL.Text:='select up from UP_DEF where prd_no='+bh+'';
    datamodule2.pricequery.SQL.Text:='select up from UP_DEF where prd_no='''+bh+'''';
    我用第一句时象我问的问题里面报错,如果用第二句就不报错了!真是奇怪了!希望大家发表看法!
      

  4.   

    这个不是很清楚嘛
    你在SQL里写 where Field1 = 12345678900000,是要把后面内容作为整数来比较的,当然了,如果你的字段的内容是字符串,那么SQL解析的时候会再把这个整数转为字符串来比较的。但是因为太大,所以转整数时就直接出错了。
    而写成 where Field2 = '123456789000000',是比较字段和一个字符串,当然就没问题了。
      

  5.   

    这里其实是SQL语句中" ' "号的匹配问题,就是SQL语句中如果需要一个'' 必需使用四个'''',因为:
    1.只给一个则认为与句首的“ 'sel..”中的相匹配,后面的当然就不认作是字串语句啦;
    2.出现两个时也可以认为是把第二个转义为一个 '。