with AdoQuery1 do
begin
SQL.Clear;
SQL.Add('insert into wxd_tab(dh,p,khdz,fwxs,khdh) values(:dh,:p,:khdz,:fwxs,:khdh)'); //,:djy
dh:=DanHao();
parameters.ParamByName('dh').Value:=dh;
parameters.ParamByName('p').value:=false;
parameters.ParamByName('khDz').value:=trim((Edit_khdz.text));
parameters.ParamByName('fwxs').value:=trim((ComboBox_fwxs.Text));
parameters.ParamByName('khdh').Value:=Edit_khdh.text;
ExecSQL;
end;
程序报错如下:
Project WXXT.exe raised exception class EOleException with message 'varchar 值 ‘13763340180/82500365'的转换溢出了 int 列。超出最大整数值。’
经过分析,错误是在 parameters.ParamByName('khdh').Value:=Edit_khdh.text;
我在 Edit_khdh.text输入82500365 就没问题,但是输入 13763340180/82500365'就报错了,奇怪,在数据库那里,我对khdh 列的定义是 varchar 100 的啊,怎么会有int 转换的??
begin
SQL.Clear;
SQL.Add('insert into wxd_tab(dh,p,khdz,fwxs,khdh) values(:dh,:p,:khdz,:fwxs,:khdh)'); //,:djy
dh:=DanHao();
parameters.ParamByName('dh').Value:=dh;
parameters.ParamByName('p').value:=false;
parameters.ParamByName('khDz').value:=trim((Edit_khdz.text));
parameters.ParamByName('fwxs').value:=trim((ComboBox_fwxs.Text));
parameters.ParamByName('khdh').Value:=Edit_khdh.text;
ExecSQL;
end;
程序报错如下:
Project WXXT.exe raised exception class EOleException with message 'varchar 值 ‘13763340180/82500365'的转换溢出了 int 列。超出最大整数值。’
经过分析,错误是在 parameters.ParamByName('khdh').Value:=Edit_khdh.text;
我在 Edit_khdh.text输入82500365 就没问题,但是输入 13763340180/82500365'就报错了,奇怪,在数据库那里,我对khdh 列的定义是 varchar 100 的啊,怎么会有int 转换的??
Type Range Format
Shortint -128..127 signed 8-bit
Smallint -32768..32767 signed 16-bit
Longint -2147483648..2147483647 signed 32-bit
Int64 -2^63..2^63-1 signed 64-bit
Byte
0..255
unsigned 8-bit
Word
0..65535
unsigned 16-bit
Longword
0..4294967295
unsigned 32-bit
你的数据库是varchar型的,要加''的。 parameters.ParamByName('khDz').value:=QuotedStr(trim(Edit_khdz.text));
ADOConnection1.execute('insert into wxd_tab(dh,p,khdz,fwxs,khdh) values('+Quotedstr(dh)+',false,'+Quotestr((Edit_khdz.text)+','+Quotedstr(ComboBox_fwxs.Text)+','+Quotedstr(Edit_khdh.text)+')');
Project WXXT.exe raised exception class EOleException with message 'varchar 值 ''13763340180/82500365''的转换溢出了 int 列。超出最大整数值。'注意多了 ' ' ,问题是为什么会转换 int列的?? 我在Edit_khdh.text 输入数字,实际上不是把数字 变成了字符了的吗?
[id] [int] NOT NULL ,
[value] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[a1] [varchar] (1000) COLLATE Chinese_PRC_CI_AS NULL ,
[hb] [money] NULL ,
CONSTRAINT [PK_testt] PRIMARY KEY CLUSTERED
(
[id]
) ON [PRIMARY]
) ON [PRIMARY]
GO测试代码如下:
procedure TForm1.Button1Click(Sender: TObject);
begin
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert into testt(id,a1)');
sql.Add('values(:#id,:#a1)');
Parameters.ParamByName('#id').Value := 10;
Parameters.ParamByName('#a1').Value := Edit1.Text;
ExecSQL;
end;
end;
edit1.text就是你那个13763340180/82500365,没有任何问题。
在数据库那里,我对khdh 列的定义是 varchar 100 的啊,怎么会有int 转换的??
换成
parameters.ParamByName('khdh').Value:='13763340180/82500365';
试试看对不对,如果没报错,证明Edit_khdh.text有问题,如果报错,你再取ADOQuery1.sql.text看看,你生成的sql语句是什么
,依然报错,也就是说不关Edit_khdh.text的事,ADOQuery1.sql.text看了一下,很正常。nevergetwin(头球冲顶): 我按照了yuehaiyang()的办法了,问题依然啊。agui(阿贵: 高级图形用户界面) :本以为是这个问题,但是试了,不是这个问题。wudi_1982(︻┳═一) :在数据库那里,我对khdh 列的定义是 varchar 100 的啊,怎么会有int 转换的??
我测试过了,只要Edit_khdh.text数字的位数>10 则报错!当我输入是 英文的时候也报这个错!奇怪了!