程序运行的时候提醒我“数据类型varchar转换为numeric时出错”我是仿别人做的一个练习,可是别人的怎么没问题呢,请哥哥们指点一下。procedure Tform1.Button1Click(Sender: TObject);
var
maxnum,maxnum2,temp,inputnum,inputnum2:string;
newnum,newnum2,i:integer;
begin
//--------------------为新插入的进货单和进货单明细数据计算编号-------------
//计算进货单中最大编号,以便插入新的进货单数据时编号不冲突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(编号) 最大编号 from 进货单');
adoquery1.Open;
maxnum:=adoquery1.FieldByName('最大编号').asstring;//对读出的编号进行截取并将其转换为整数值,字段太长时可以不能用strtoint来转换
//防止插入第一条记录时出错
if (maxnum='')or(maxnum=' ') then
temp:='00000'
else
temp:=copy(maxnum,1,5);//新插入的进货单编号为插入前的最大编号+1
newnum:=strtoint(temp)+1;
//重新组合编码
if length(inttostr(newnum))=1 then
inputnum:='0000'+inttostr(newnum);
if length(inttostr(newnum))=2 then
inputnum:='000'+inttostr(newnum);
if length(inttostr(newnum))=3 then
inputnum:='00'+inttostr(newnum);
if length(inttostr(newnum))=4 then
inputnum:='0'+inttostr(newnum);
if length(inttostr(newnum))=5 then
inputnum:=inttostr(newnum); //计算进货单明细最大编号以便插入新的进货单明细数据时编号不冲突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(编号) 最大编号 from 进货单明细');
adoquery1.Open;
maxnum2:=adoquery1.FieldByName('最大编号').asstring;//对读出的编号进行截取并将其转换为整数值,字段太长时可以不能用strtoint来转换
//防止插入第一条记录时出错
if (maxnum2='')or(maxnum2=' ') then
temp:='00000'
else
temp:=copy(maxnum2,1,5);
newnum2:=strtoint(temp);
//由于进货单明细数据可能由很多条,因此在下面的循环中进货单明细循环种再编号和组合编码//-----------插入新的进货单和进货单明细-----------------------------
//如果供货商号为空或者时没有进货单明细数据,则取消插入----
if (combobox2.Text='')or(edit4.Text='') then
showmessage('供货商号不能为空,且进货单明细数据必须完整')
else
begin
//插入新的进货单数据
adocommand1.CommandText:='insert into 进货单([编号],[供货商号],[进货日期],[业务员],[制单人],[税价合计],[不含税价],[税额]) values('''+inputnum+''','''+combobox2.Text+''','''+edit1.Text+''','''+combobox1.Text+''','''+edit2.Text+''','''+edit4.Text+''','''+edit5.Text+''','''+edit6.Text+''')';
adocommand1.Execute;
//根据进货单明细条目的数量,插入进货单明细数据
for i:=1 to 20 do
if stringgrid1.Cells[7,i]<>'' then
//重新组合编码
begin
newnum2:=newnum2+1;
if length(inttostr(newnum2))=1 then
inputnum2:='0000'+inttostr(newnum2);
if length(inttostr(newnum2))=2 then
inputnum2:='000'+inttostr(newnum2);
if length(inttostr(newnum2))=3 then
inputnum2:='00'+inttostr(newnum2);
if length(inttostr(newnum2))=4 then
inputnum2:='0'+inttostr(newnum2);
if length(inttostr(newnum2))=5 then
inputnum2:=inttostr(newnum2);
adocommand1.CommandText:='insert into 进货单明细([编号],[进货单号],[货号],[进货数量],[进价],[税价合计],[税率],[不含税价],[税额],[仓库]) values('''+inputnum2+''','''+inputnum+''','''+stringgrid1.Cells[1,i]+''','''+stringgrid1.Cells[4,i]+''','''+stringgrid1.Cells[6,i]+''','''+stringgrid1.Cells[7,i]+''','''+stringgrid1.Cells[8,i]+''','''+stringgrid1.Cells[10,i]+''','''+stringgrid1.Cells[9,i]+''','''+stringgrid1.Cells[5,i]+''')';
adocommand1.Execute;
end;
//通知用户,操作成功
showmessage('进货单及明细保存成功'); end;
end;
var
maxnum,maxnum2,temp,inputnum,inputnum2:string;
newnum,newnum2,i:integer;
begin
//--------------------为新插入的进货单和进货单明细数据计算编号-------------
//计算进货单中最大编号,以便插入新的进货单数据时编号不冲突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(编号) 最大编号 from 进货单');
adoquery1.Open;
maxnum:=adoquery1.FieldByName('最大编号').asstring;//对读出的编号进行截取并将其转换为整数值,字段太长时可以不能用strtoint来转换
//防止插入第一条记录时出错
if (maxnum='')or(maxnum=' ') then
temp:='00000'
else
temp:=copy(maxnum,1,5);//新插入的进货单编号为插入前的最大编号+1
newnum:=strtoint(temp)+1;
//重新组合编码
if length(inttostr(newnum))=1 then
inputnum:='0000'+inttostr(newnum);
if length(inttostr(newnum))=2 then
inputnum:='000'+inttostr(newnum);
if length(inttostr(newnum))=3 then
inputnum:='00'+inttostr(newnum);
if length(inttostr(newnum))=4 then
inputnum:='0'+inttostr(newnum);
if length(inttostr(newnum))=5 then
inputnum:=inttostr(newnum); //计算进货单明细最大编号以便插入新的进货单明细数据时编号不冲突
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(编号) 最大编号 from 进货单明细');
adoquery1.Open;
maxnum2:=adoquery1.FieldByName('最大编号').asstring;//对读出的编号进行截取并将其转换为整数值,字段太长时可以不能用strtoint来转换
//防止插入第一条记录时出错
if (maxnum2='')or(maxnum2=' ') then
temp:='00000'
else
temp:=copy(maxnum2,1,5);
newnum2:=strtoint(temp);
//由于进货单明细数据可能由很多条,因此在下面的循环中进货单明细循环种再编号和组合编码//-----------插入新的进货单和进货单明细-----------------------------
//如果供货商号为空或者时没有进货单明细数据,则取消插入----
if (combobox2.Text='')or(edit4.Text='') then
showmessage('供货商号不能为空,且进货单明细数据必须完整')
else
begin
//插入新的进货单数据
adocommand1.CommandText:='insert into 进货单([编号],[供货商号],[进货日期],[业务员],[制单人],[税价合计],[不含税价],[税额]) values('''+inputnum+''','''+combobox2.Text+''','''+edit1.Text+''','''+combobox1.Text+''','''+edit2.Text+''','''+edit4.Text+''','''+edit5.Text+''','''+edit6.Text+''')';
adocommand1.Execute;
//根据进货单明细条目的数量,插入进货单明细数据
for i:=1 to 20 do
if stringgrid1.Cells[7,i]<>'' then
//重新组合编码
begin
newnum2:=newnum2+1;
if length(inttostr(newnum2))=1 then
inputnum2:='0000'+inttostr(newnum2);
if length(inttostr(newnum2))=2 then
inputnum2:='000'+inttostr(newnum2);
if length(inttostr(newnum2))=3 then
inputnum2:='00'+inttostr(newnum2);
if length(inttostr(newnum2))=4 then
inputnum2:='0'+inttostr(newnum2);
if length(inttostr(newnum2))=5 then
inputnum2:=inttostr(newnum2);
adocommand1.CommandText:='insert into 进货单明细([编号],[进货单号],[货号],[进货数量],[进价],[税价合计],[税率],[不含税价],[税额],[仓库]) values('''+inputnum2+''','''+inputnum+''','''+stringgrid1.Cells[1,i]+''','''+stringgrid1.Cells[4,i]+''','''+stringgrid1.Cells[6,i]+''','''+stringgrid1.Cells[7,i]+''','''+stringgrid1.Cells[8,i]+''','''+stringgrid1.Cells[10,i]+''','''+stringgrid1.Cells[9,i]+''','''+stringgrid1.Cells[5,i]+''')';
adocommand1.Execute;
end;
//通知用户,操作成功
showmessage('进货单及明细保存成功'); end;
end;
解决方案 »
- 急寻求汉字拼音对照表,100分相赠!!
- 请教Binary Stream和AnsiString如何互相转换......
- 这个问题好难,MM发了很多个贴子了也还没能解决,请各位高手帮帮我(关于数据库中一条记录打印)
- 用Delphi开发杀毒软件
- 关于Data: Pointer;的 现在知道pointer 类型,和它的大小SIZE 能用什么办法把它当成memorystream从网路上传输然后在恢复过来呢?
- 哪位有适合Delphi用的两态图标?
- 来看看
- Terminate是请求结束一个线程,那么如何真正结束一个线程呢?
- help me 小弟是新手
- 请问inc()是什么函数,主要作用是什么,在C++中有无对应的函数?谢谢大家
- 磁盘容量不足,SQL插入操作CPU100%
- delphi 如何切割合并视频文件 求思路
以上字段各是什么类型?2楼的应该是正确的,如果仍报同一个错误,是不是你的(供货商号)是数字?adocommand1.CommandText:='insert into 进货单([编号],[供货商号],[进货日期],[业务员],[制单人],[税价合计],[不含税价],[税额]) values('''+inputnum+''','+combobox2.Text+','''+edit1.Text+''','''+combobox1.Text+''','''+edit2.Text+''','+edit4.Text+','+edit5.Text+','+edit6.Text+')';
如果不是同一个错误,把错误提示贴出来~~
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select max(编号) AS 最大编号 from 进货单');
adoquery1.Open;
maxnum:=adoquery1.FieldByName('最大编号').asstring; 加个 AS