delphi field 'id' cannot be modified 在线等高手!!!急呀

时间:2021-07-19 14:40:38
用delphi做汽配管理系统,产品入库的时候,点击保存到临时表,就跳出这个错误了,我的数据库是access,rklsb是表名,那个id是在rklsb里是自动编号的,用到adotable,adoquery
---------------------------
adoQuery1.SQL.Clear;
 adoQuery1.SQL.Add('Delete from rklsb');
 adoQuery1.ExecSQL;
 adoquery1.Close;
------------------------------------------

 while not adotable1.eof do begin
     adotable1.delete;
   end;
-----------------------------------------------

我也是初学者,不知道怎么描述问题,是不是错在这两句上还是其他地方?

13 个解决方案

#1


应当是自动编号的字段,不允许进行修改的原因,
在程序中不要修改这个字段的值估计就可以了
你上边的代码中好像没有处理这个ID的地方,可能是在其它地方出的问题吧

#2


引用 1 楼 sonicer 的回复:
应当是自动编号的字段,不允许进行修改的原因,
在程序中不要修改这个字段的值估计就可以了
你上边的代码中好像没有处理这个ID的地方,可能是在其它地方出的问题吧


我也不知道哪里出错了,我另外还有个出库的功能,也是到保存临时表的时候就出现这问题,你能帮我看看程序吗

#3


id不要作为字段名

改一下

#4


引用 3 楼 brightyang 的回复:
id不要作为字段名

改一下

那改成什么?表里面就有的

#5


在保存的时候不要对ID字符操作,仔细检查一下你的保存代码

#6


可是我有很多其他表也有id,进行操作都没有关系呀

怎么发附件呀,我好想把程序发上来大家看看呀

#7


procedure TCPRK.FormCreate(Sender: TObject);   //初始化
begin
 adoQuery1.SQL.Clear;
 adoQuery1.SQL.Add('Delete from rklsb');
 adoQuery1.ExecSQL;
 adoquery1.Close;
 adotable1.tablename:='rklsb';
 adotable1.open;
 adotable2.tablename:='kehu';
 adotable2.open;
  adotable3.tablename:='chanji';
 adotable3.open;
 adotable4.tablename:='kc';
 adotable4.open;
 adotable5.tablename:='jdb';
 adotable5.open;
 adotable6.tablename:='chanrk';
 adotable6.open;
 adotable7.tablename:='chanrk';
 adotable7.open;
 adotable8.tablename:='jdb';
 adotable8.open;
 adotable9.tablename:='rpiao';
 adotable9.open;
end;
procedure TCPRK.FormShow(Sender: TObject); //设置控件属性
begin
 radiobutton2.Checked:=true;
 edit7.enabled:=true;
 edit8.enabled:=false;
 speedbutton1.Visible:=false;
 groupbox4.enabled:=false;
 speedbutton2.visible:=false;
 bitbtn1.enabled:=true;
 bitbtn2.enabled:=false;
 bitbtn3.enabled:=false;
 adoquery1.Active:=false;
 edit1.text:='0';
 edit2.text:='0';
 edit3.text:='0';
 adotable9.first;
 while not adotable9.eof do begin
   combobox1.Items.add(adotable9.fieldbyname('piao').asstring);
   adotable9.next;
   end;
 edit7.setfocus;
end;
procedure TCPRK.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then      //回车移动焦点
   If (ActiveControl Is Tedit) Then  PerForm(WM_NextDlgctl,0,0);
end;

procedure TCPRK.RadioButton2Click(Sender: TObject);  //使用客户编号录入客户信息
begin
 edit7.enabled:=true;
 edit8.enabled:=false;
 speedbutton1.visible:=false;
 edit7.setfocus;
end;
procedure TCPRK.RadioButton1Click(Sender: TObject);  //使用客户名称录入客户信息
begin
 edit8.enabled:=true;
 edit7.enabled:=false;
 speedbutton1.Visible:=false;
 edit8.setfocus;
end;

procedure TCPRK.RadioButton3Click(Sender: TObject); //使用快捷方式录入客户信息
begin
 edit7.enabled:=false;
 edit8.Enabled:=false;
 speedbutton1.visible:=true;
end;

procedure TCPRK.SpeedButton1Click(Sender: TObject);  //调入客户信息列表
begin
 Application.CreateForm(TKHXXGL,KHXXGL);
 KHXXGL.showmodal;
end;
procedure TCPRK.RadioButton4Click(Sender: TObject); //使用产品编号选择商品
begin
 edit12.enabled:=true;
 edit13.enabled:=false;
 edit14.enabled:=false;
 speedbutton2.Visible:=false;
 edit12.setfocus;
end;
procedure TCPRK.RadioButton5Click(Sender: TObject); //使用产品型号选择商品
begin
 edit12.enabled:=false;
 edit13.enabled:=true;
 edit14.enabled:=true;
 speedbutton2.visible:=false;
 edit13.setfocus;
end;
procedure TCPRK.RadioButton6Click(Sender: TObject);  //使用快捷键选择商品
begin
 EDIT12.enabled:=false;
 edit13.enabled:=false;
 edit14.enabled:=false;
 speedbutton2.visible:=true;
end;
procedure TCPRK.SpeedButton2Click(Sender: TObject); //调入商品信息列表
begin
 Application.CreateForm(TCPXXcx,CPXXcx);
 CPXXcx.showmodal;
end;
procedure TCPRK.BitBtn1Click(Sender: TObject);  //登记
var year,month,day:word; i:integer;
begin
 i:=0;
 try
 if edit7.text<>'' then begin
  adotable9.open;
  adotable9.first;
  while not adotable9.eof do begin
    I:=I+1;
    adotable9.next;
  end;
  decodedate(now,year,month,day);
  combobox1.text:=inttostr(year)+inttostr(month)+inttostr(day)+'0'+inttostr(i);//生成入库票号
  combobox1.enabled:=false;
   datasource1.DataSet:=adotable1;
   adotable1.open;
   bitbtn5.enabled:=true; bitbtn6.enabled:=true; bitbtn1.enabled:=false;
   bitbtn2.enabled:=true; bitbtn3.enabled:=true;bitbtn4.enabled:=false;
   edit12.visible:=true; edit13.visible:=true; edit14.visible:=true;
   edit15.visible:=true; edit16.visible:=true; edit17.visible:=true;
   edit18.visible:=true; edit19.visible:=true; edit20.visible:=true;
   edit21.visible:=true;edit22.visible:=true;
   edit12.Text:='';  edit13.text:='';  edit14.text:='';  edit15.text:='';
   edit16.text:='';  edit17.text:='';  edit18.text:='';  edit19.text:='';
   edit20.text:='';  edit21.text:='';  edit22.text:='';  edit12.enabled:=true;
   edit13.enabled:=false;  edit14.enabled:=false;   speedbutton2.visible:=false;
   edit12.setfocus;
   adotable1.First;
   groupbox4.enabled:=true;
   radiobutton4.Checked:=true;
   while not adotable1.eof do begin
     adotable1.delete;
   end;
   end else begin
    showmessage('请将客户信息添全。');
   end;
   except
    showmessage('数据不能连接。');
   end;
  BITBTN2.Enabled:=FALSE;
end;
procedure TCPRK.BitBtn3Click(Sender: TObject);   //取消
begin
 combobox1.text:='';
 combobox1.Enabled:=true;
 adotable1.Cancel;
 bitbtn5.enabled:=false; bitbtn6.enabled:=false;  bitbtn1.enabled:=true;
 bitbtn2.enabled:=false; bitbtn3.enabled:=false;  bitbtn4.enabled:=true;
 edit12.visible:=false; edit13.visible:=false;  edit14.visible:=false;
 edit15.visible:=false; edit16.visible:=false;  edit17.visible:=false;
 edit18.visible:=false; edit19.visible:=false;  edit20.visible:=false;
 edit21.visible:=false; edit22.visible:=false; groupbox4.enabled:=true;
 groupbox4.enabled:=false;
 adotable7.open;
 adotable1.First;
 while not adotable1.eof do begin
    adotable1.delete;
    end;
 adotable9.Active:=false;
end;

#8


procedure TCPRK.BitBtn2Click(Sender: TObject);  //入库
var i:string;
begin
   try  i:='';
   If strtoint(edit2.Text) <> strtoint(edit3.Text) Then begin   //如应付与实付不符
    showmessage('实付款于应付款不符,系统将建立借贷关系。');
    adotable1.first;
    while not adotable1.eof do begin
       I:=I+'[产品名称:('+adotable1.fieldbyname('cpmc').asstring+')数量:('+adotable1.fieldbyname('shuliang').asstring+')];      ';
       adotable1.next;
    end;
    adotable8.insert;       //保存欠款到借贷表
    adotable8.fieldbyname('piao').asstring:=combobox1.text;
    adotable8.fieldbyname('jsr').asstring:=mrqp.label1.caption;
    adotable8.fieldbyname('rdate').asdatetime:=date;
    adotable8.fieldbyname('shuliang').asstring:=edit1.text;
    adotable8.fieldbyname('khbh').asstring:=edit7.text;
    adotable8.fieldbyname('khqc').asstring:=edit8.Text;
    adotable8.fieldbyname('lxdh').asstring:=edit9.text;
    adotable8.fieldbyname('ying').asinteger:=strtoint(edit2.text);
    adotable8.fieldbyname('shi').asinteger:=strtoint(edit3.text);
    adotable8.fieldbyname('huo').asstring:='入库';
    adotable8.fieldbyname('chanpin').asstring:=i;
    If strtoint(edit2.Text) < strtoint(edit3.Text) Then begin
      adotable8.fieldbyname('zhaigx').asstring:='借出';
      adotable8.fieldbyname('zhai').asinteger:=strtoint(edit3.text)-strtoint(edit2.text);
    end else begin
      adotable8.fieldbyname('zhaigx').asstring:='借入';
      adotable8.fieldbyname('zhai').asinteger:=strtoint(edit2.text)-strtoint(edit3.text);
    end;
    adotable8.post;
   end;
   adotable1.cancel;
   adotable1.First;
   while not adotable1.eof do begin
    if adotable4.Locate('cpbh',adotable1.fieldbyname('cpbh').asstring,[Lopartialkey]) then begin //查询商品
       adotable4.edit;       //库存增加
       adotable4.FieldByName('shuliang').asinteger:=adotable4.fieldbyname('shuliang').asinteger+adotable1.fieldbyname('shuliang').asinteger;
       adotable4.fieldbyname('je').asinteger:=adotable4.fieldbyname('je').asinteger+adotable1.fieldbyname('je').asinteger;
       adotable4.fieldbyname('shi').asinteger:=adotable4.fieldbyname('shi').asinteger+adotable1.fieldbyname('shi').asinteger;
       adotable4.post;
       End
     Else begin
       adotable4.InsertRecord([adotable1.fieldbyname('cpbh').asstring,adotable1.fieldbyname('cpmc').asstring,
            adotable1.fieldbyname('cpxh').asstring,adotable1.fieldbyname('cpbs').asstring,adotable1.fieldbyname('danjia').asinteger,
            adotable1.fieldbyname('dan').asstring,adotable1.fieldbyname('shuliang').asstring,adotable1.fieldbyname('cx').asstring,
            adotable1.fieldbyname('cd').asstring,adotable1.fieldbyname('pi').asstring,adotable1.fieldbyname('ling').asstring,
            adotable1.fieldbyname('jy').asstring,adotable1.fieldbyname('je').asstring,adotable1.fieldbyname('shi').asstring]);
       adotable4.post;
     end;
     adotable7.insert;  //保存入库到入库单
     adotable7.fieldbyname('piao').asstring:=combobox1.text;
     adotable7.FieldByName('cpbh').asstring:= adotable1.fieldbyname('cpbh').asstring;
     adotable7.fieldbyname('cpmc').asstring:=adotable1.fieldbyname('cpmc').asstring;
     adotable7.FieldByName('cpxh').asstring:= adotable1.fieldbyname('cpxh').asstring;
     adotable7.fieldbyname('cpbh').asstring:= adotable1.fieldbyname('cpbh').asstring;
     adotable7.fieldbyname('cpbs').asstring:= adotable1.fieldbyname('cpbs').asstring;
     adotable7.fieldbyname('danjia').asstring:= adotable1.fieldbyname('danjia').asstring;
     adotable7.fieldbyname('dan').asstring:=adotable1.fieldbyname('dan').asstring;
     adotable7.fieldbyname('cx').asstring:=adotable1.fieldbyname('cx').asstring;
     adotable7.fieldbyname('cd').asstring:=adotable1.fieldbyname('cd').asstring;
     adotable7.fieldbyname('pi').asinteger:= adotable1.fieldbyname('pi').asinteger;
     adotable7.fieldbyname('ling').asinteger:= adotable1.fieldbyname('ling').asinteger;
     adotable7.fieldbyname('jy').asinteger:=adotable1.fieldbyname('jy').asinteger;
     adotable7.FieldByName('je').asinteger:=adotable1.fieldbyname('je').asinteger;
     adotable7.fieldbyname('shi').asinteger:=adotable1.fieldbyname('shi').asinteger;
     adotable7.fieldbyname('shuliang').asstring:= adotable1.fieldbyname('shuliang').asstring;
     adotable7.fieldbyname('khbh').asstring:= adotable1.fieldbyname('khbh').asstring;
     adotable7.fieldbyname('khqc').asstring:= adotable1.fieldbyname('khqc').asstring;
     adotable7.fieldbyname('lxdh').asstring:= adotable1.fieldbyname('lxdh').asstring;
     adotable7.fieldbyname('lxr').asstring:= adotable1.fieldbyname('lxr').asstring;
     adotable7.fieldbyname('sj').asstring:= adotable1.fieldbyname('sj').asstring;
     adotable7.fieldbyname('di').asstring:= adotable1.fieldbyname('di').asstring;
     adotable7.fieldbyname('yb').asstring:= adotable1.fieldbyname('yb').asstring;
     adotable7.fieldbyname('jsr').asstring:= adotable1.fieldbyname('jsr').asstring;
     adotable7.fieldbyname('rdate').asdatetime:= adotable1.fieldbyname('rdate').asdatetime;
     adotable7.fieldbyname('shi').asinteger:= adotable1.fieldbyname('shi').asinteger;
    adotable7.post;
    adotable1.delete;
   end;
  adotable9.insert;    //增加票号到票号表
  adotable9.fieldbyname('piao').asstring:=combobox1.Text;
  combobox1.Items.add(combobox1.text);
  adotable9.Post;
  adotable9.active:=false;
  combobox1.Text:='';
  combobox1.enabled:=true;
  datasource1.DataSet:=adotable7;    //查看库存情况
  adotable7.open;
  adotable1.Cancel;
  bitbtn5.enabled:=false;
  bitbtn6.Enabled:=false;
  bitbtn1.enabled:=true;
  bitbtn2.enabled:=false;
  bitbtn3.enabled:=false;
  bitbtn4.enabled:=true;
  groupbox4.enabled:=false;
  groupbox4.enabled:=false;
 except
 showmessage('数据有误,无法入库。');
 end;
end;
procedure TCPRK.ComboBox1Click(Sender: TObject);
begin
if combobox1.text='所有记录' then begin
adotable7.filtered:=false;
end else begin
adotable7.Filtered:=true;
adotable7.filter:=format('piao'+'='+'''%s''',[combobox1.text]);
end;
end;
procedure TCPRK.BitBtn5Click(Sender: TObject);
begin
edit12.text:='';
edit13.text:='';
edit14.text:='';
edit15.text:='';
edit16.text:='';
edit17.text:='';
edit18.text:='';
edit19.text:='';
edit20.text:='';
edit21.text:='';
edit22.text:='';
edit12.setfocus;
end;
procedure TCPRK.Edit3Exit(Sender: TObject);
begin
if edit3.text='' then begin
   edit3.text:='0'
   end;
end;
procedure TCPRK.Edit7KeyPress(Sender: TObject; var Key: Char);  //利用客户编号选择客户信息
begin
 if key=#13 then begin     //回车
  if edit7.text<>'' then begin
  edit8.text:='';
  edit9.text:='';
  edit10.text:='';
  edit4.Text:='';
  edit5.text:='';
  edit6.text:='';
  if adotable2.Locate('khbh',edit7.text,[Lopartialkey]) then begin    //查找客户
   edit7.text:=adotable2.fieldbyname('khbh').asstring;     //填入客户信息
   edit8.text:=adotable2.fieldbyname('khqc').asstring;
   edit9.text:=adotable2.fieldbyname('lxdh').asstring;
   edit6.text:=adotable2.fieldbyname('lxr').asstring;
   edit5.text:=adotable2.fieldbyname('sj').asstring;
   edit4.text:=adotable2.fieldbyname('di').asstring;
   edit10.text:=adotable2.fieldbyname('yb').asstring;
  End
  Else begin
     showmessage('系统中无此编号,请添加。');
  end;
  bitbtn1.setfocus;
  end;
 end;
 if (key<'0') or (key>'9') or (key=#8)then key:=#0;
end;

#9


用id做字段名应该是没有问题的,我就经常这么做。
楼主说的不明白,没有弄懂。不过写查询语名一般是这样的:
adoquery1.Close;//先关闭query
adoQuery1.SQL.Clear; //再清空其内容
adoQuery1.SQL.Add('Delete from rklsb'); //加上查询的内容
adoQuery1.ExecSQL; //最后执行

退出此窗口时加上adoquery1.Close;也行,在ExecSQL后加恐怕要出问题。

#10


procedure TCPRK.Edit8KeyPress(Sender: TObject; var Key: Char);  //选择客户信息
begin
if edit8.text<>'' then begin
if adotable2.Locate('khqc',edit8.text,[Lopartialkey]) then begin
   edit7.text:=adotable2.fieldbyname('khbh').asstring;
   edit8.text:=adotable2.fieldbyname('khqc').asstring;
   edit9.text:=adotable2.fieldbyname('lxdh').asstring;
   edit6.text:=adotable2.fieldbyname('lxr').asstring;
   edit5.text:=adotable2.fieldbyname('sj').asstring;
   edit4.text:=adotable2.fieldbyname('di').asstring;
   edit10.text:=adotable2.fieldbyname('yb').asstring;
   End
Else begin
   showmessage('系统中无此名称,请添加。');
   end;
end;
end;
procedure TCPRK.Edit12KeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin //回车选择产品信息
 edit21.text:='';
 edit13.text:='';
 edit14.text:='';
 edit15.text:='';
 edit16.text:='';
 edit17.text:='';
 edit18.text:='';
 edit19.text:='';
 edit20.text:='';
 edit22.text:='';
 if adotable3.locate('cpbh',edit12.text,[loCaseInsensitive]) then   //查询产品信息
   begin
     edit12.text:=adotable3.fieldbyname('cpbh').asstring;
     edit13.text:=adotable3.fieldbyname('cpmc').asstring;
     edit14.text:=adotable3.fieldbyname('cpxh').asstring;
     edit16.text:=inttostr(adotable3.fieldbyname('pi').asinteger);
     edit17.text:=inttostr(adotable3.fieldbyname('ling').asinteger);
     edit18.text:=inttostr(adotable3.fieldbyname('jy').asinteger);
     a11:=adotable3.fieldbyname('dan').asstring;
     edit19.text:=inttostr(adotable3.fieldbyname('danjia').asinteger);
     a12:=adotable3.fieldbyname('cx').asstring;
     a13:=adotable3.fieldbyname('cd').asstring;
     End
 Else
     begin
     showmessage('系统中无此编号,请添加。');
     end;
 edit15.SetFocus;
 end;
end;

procedure TCPRK.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
   if edit13.text<>'' then
        edit14.SetFocus
   Else begin
        key:=#0;
        showmessage('请输入产品名称。');
   end;
end;

procedure TCPRK.Edit14KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then begin     //回车利用产品型号选择产品
if adotable3.locate('cpmc;cpxh',vararrayof([edit13.text,edit14.text]),[loCaseInsensitive]) then
  begin
    edit12.text:=adotable3.fieldbyname('cpbh').asstring;
    edit13.text:=adotable3.fieldbyname('cpmc').asstring;
    edit14.text:=adotable3.fieldbyname('cpxh').asstring;
    edit16.text:=inttostr(adotable3.fieldbyname('pi').asinteger);
    edit17.text:=inttostr(adotable3.fieldbyname('ling').asinteger);
    edit18.text:=inttostr(adotable3.fieldbyname('jy').asinteger);
    a11:=adotable3.fieldbyname('dan').asstring;
    edit19.text:=inttostr(adotable3.fieldbyname('danjia').asinteger);
    a12:=adotable3.fieldbyname('cx').asstring;
    a12:=adotable3.fieldbyname('cd').asstring;
    edit15.setfocus;
    End
Else
    begin
    showmessage('系统中无此型号,请添加。');
    end;
 end;
end;
procedure TCPRK.Edit20KeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin
  try
  if edit20.text='' then edit20.text:='0';
  edit21.text:=inttostr(strtoint(edit20.text)* strtoint(edit19.text)); //计算应付金额
  edit22.Text:=edit21.text;   //实付金额
  //table1.fieldbyname('shi').asinteger:=table1.fieldbyname('je').asinteger;
  edit22.setfocus;
  except
  showmessage('不能运算!');
  end;
 end;
end;
procedure TCPRK.Edit22KeyPress(Sender: TObject; var Key: Char); //回车焦点Button1
begin
  if key=#13 then begin
  Button1.SetFocus ;
end;
end;
procedure TCPRK.Edit19KeyPress(Sender: TObject; var Key: Char);  //比较价格
var add:integer;
begin
 if key=#13 then begin
  try
  adotable6.Refresh;
  adotable6.Filtered:=true;
  adotable6.filter:=format('cpmc'+'='+'''%s''',[edit13.text]);
  if adotable6.Locate('cpmc',edit13.text,[Lopartialkey]) //查询商品
   then begin
   adotable6.last;
   add:=adotable6.fieldbyname('danjia').asinteger; end
   Else begin
    add:=adotable3.fieldbyname('danjia').asinteger; end ;
  if strtoint(edit19.text)>add then begin        //比较进价
     showmessage('本次进货价高于上次,请三思后保存。');
     end;
  edit20.setfocus;
  except on exception do showmessage('数据无法计算,请核实。');
  end;
 end;
end;
procedure TCPRK.Button1Click(Sender: TObject);  // 保存数据到临时表
begin
 try
 adotable1.open;
 adotable1.AppendRecord([edit12.text,edit13.text,edit14.text,edit15.text,
       mrqp.label1.caption,date,edit19.text,a11,edit20.text,a12,a13,
       edit7.text,edit8.text,edit4.text,edit9.text,edit6.text,edit5.text,
       edit10.text,strtoint(edit16.text),strtoint(edit17.text),strtoint(edit18.text),
       strtoint(edit21.text),strtoint(edit21.text),strtoint(edit22.text)]);
  edit1.text:=inttostr(strtoint(edit1.text)+strtoint(edit20.text));
  edit2.text:=inttostr(strtoint(edit2.text)+strtoint(edit21.text));
  edit3.text:=inttostr(strtoint(edit3.text)+strtoint(edit22.text));
  edit12.text:=''; edit13.text:=''; edit14.text:='';edit15.text:='';
 edit16.text:='';edit17.text:=''; edit18.text:=''; edit19.text:='';
 edit20.text:='';edit21.text:=''; edit22.text:='';
 if radiobutton4.Checked then edit12.setfocus;
 if radiobutton5.checked then edit13.setfocus;
 if radiobutton6.checked then bitbtn2.setfocus;
 BITBTN2.Enabled:=TRUE;

 except
 showmessage('输入格式错误。');
 end;
end;
procedure TCPRK.BitBtn4Click(Sender: TObject);   //退出
begin
 close;
end;
end.

#11


引用 9 楼 wjs_002 的回复:
用id做字段名应该是没有问题的,我就经常这么做。
楼主说的不明白,没有弄懂。不过写查询语名一般是这样的:
adoquery1.Close;//先关闭query
adoQuery1.SQL.Clear; //再清空其内容
adoQuery1.SQL.Add('Delete from rklsb'); //加上查询的内容
adoQuery1.ExecSQL; //最后执行

退出此窗口时加上adoquery1.Close;也行,在ExecSQL后加恐怕要出问题。


我也觉得问题不是出在这里,可是我找不出问题,于是就描述不清
你的方法试过了没用

#12


自动编号列删除,试试看!要不就不要用自动编号!自己编号!

#13


id是自动编号的吧。。。。既然设置了自动编号,那代码中就不要再id:=id+1了。。。。

或者就把数据库里id别设为自动编号

二选一

#1


应当是自动编号的字段,不允许进行修改的原因,
在程序中不要修改这个字段的值估计就可以了
你上边的代码中好像没有处理这个ID的地方,可能是在其它地方出的问题吧

#2


引用 1 楼 sonicer 的回复:
应当是自动编号的字段,不允许进行修改的原因,
在程序中不要修改这个字段的值估计就可以了
你上边的代码中好像没有处理这个ID的地方,可能是在其它地方出的问题吧


我也不知道哪里出错了,我另外还有个出库的功能,也是到保存临时表的时候就出现这问题,你能帮我看看程序吗

#3


id不要作为字段名

改一下

#4


引用 3 楼 brightyang 的回复:
id不要作为字段名

改一下

那改成什么?表里面就有的

#5


在保存的时候不要对ID字符操作,仔细检查一下你的保存代码

#6


可是我有很多其他表也有id,进行操作都没有关系呀

怎么发附件呀,我好想把程序发上来大家看看呀

#7


procedure TCPRK.FormCreate(Sender: TObject);   //初始化
begin
 adoQuery1.SQL.Clear;
 adoQuery1.SQL.Add('Delete from rklsb');
 adoQuery1.ExecSQL;
 adoquery1.Close;
 adotable1.tablename:='rklsb';
 adotable1.open;
 adotable2.tablename:='kehu';
 adotable2.open;
  adotable3.tablename:='chanji';
 adotable3.open;
 adotable4.tablename:='kc';
 adotable4.open;
 adotable5.tablename:='jdb';
 adotable5.open;
 adotable6.tablename:='chanrk';
 adotable6.open;
 adotable7.tablename:='chanrk';
 adotable7.open;
 adotable8.tablename:='jdb';
 adotable8.open;
 adotable9.tablename:='rpiao';
 adotable9.open;
end;
procedure TCPRK.FormShow(Sender: TObject); //设置控件属性
begin
 radiobutton2.Checked:=true;
 edit7.enabled:=true;
 edit8.enabled:=false;
 speedbutton1.Visible:=false;
 groupbox4.enabled:=false;
 speedbutton2.visible:=false;
 bitbtn1.enabled:=true;
 bitbtn2.enabled:=false;
 bitbtn3.enabled:=false;
 adoquery1.Active:=false;
 edit1.text:='0';
 edit2.text:='0';
 edit3.text:='0';
 adotable9.first;
 while not adotable9.eof do begin
   combobox1.Items.add(adotable9.fieldbyname('piao').asstring);
   adotable9.next;
   end;
 edit7.setfocus;
end;
procedure TCPRK.FormKeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then      //回车移动焦点
   If (ActiveControl Is Tedit) Then  PerForm(WM_NextDlgctl,0,0);
end;

procedure TCPRK.RadioButton2Click(Sender: TObject);  //使用客户编号录入客户信息
begin
 edit7.enabled:=true;
 edit8.enabled:=false;
 speedbutton1.visible:=false;
 edit7.setfocus;
end;
procedure TCPRK.RadioButton1Click(Sender: TObject);  //使用客户名称录入客户信息
begin
 edit8.enabled:=true;
 edit7.enabled:=false;
 speedbutton1.Visible:=false;
 edit8.setfocus;
end;

procedure TCPRK.RadioButton3Click(Sender: TObject); //使用快捷方式录入客户信息
begin
 edit7.enabled:=false;
 edit8.Enabled:=false;
 speedbutton1.visible:=true;
end;

procedure TCPRK.SpeedButton1Click(Sender: TObject);  //调入客户信息列表
begin
 Application.CreateForm(TKHXXGL,KHXXGL);
 KHXXGL.showmodal;
end;
procedure TCPRK.RadioButton4Click(Sender: TObject); //使用产品编号选择商品
begin
 edit12.enabled:=true;
 edit13.enabled:=false;
 edit14.enabled:=false;
 speedbutton2.Visible:=false;
 edit12.setfocus;
end;
procedure TCPRK.RadioButton5Click(Sender: TObject); //使用产品型号选择商品
begin
 edit12.enabled:=false;
 edit13.enabled:=true;
 edit14.enabled:=true;
 speedbutton2.visible:=false;
 edit13.setfocus;
end;
procedure TCPRK.RadioButton6Click(Sender: TObject);  //使用快捷键选择商品
begin
 EDIT12.enabled:=false;
 edit13.enabled:=false;
 edit14.enabled:=false;
 speedbutton2.visible:=true;
end;
procedure TCPRK.SpeedButton2Click(Sender: TObject); //调入商品信息列表
begin
 Application.CreateForm(TCPXXcx,CPXXcx);
 CPXXcx.showmodal;
end;
procedure TCPRK.BitBtn1Click(Sender: TObject);  //登记
var year,month,day:word; i:integer;
begin
 i:=0;
 try
 if edit7.text<>'' then begin
  adotable9.open;
  adotable9.first;
  while not adotable9.eof do begin
    I:=I+1;
    adotable9.next;
  end;
  decodedate(now,year,month,day);
  combobox1.text:=inttostr(year)+inttostr(month)+inttostr(day)+'0'+inttostr(i);//生成入库票号
  combobox1.enabled:=false;
   datasource1.DataSet:=adotable1;
   adotable1.open;
   bitbtn5.enabled:=true; bitbtn6.enabled:=true; bitbtn1.enabled:=false;
   bitbtn2.enabled:=true; bitbtn3.enabled:=true;bitbtn4.enabled:=false;
   edit12.visible:=true; edit13.visible:=true; edit14.visible:=true;
   edit15.visible:=true; edit16.visible:=true; edit17.visible:=true;
   edit18.visible:=true; edit19.visible:=true; edit20.visible:=true;
   edit21.visible:=true;edit22.visible:=true;
   edit12.Text:='';  edit13.text:='';  edit14.text:='';  edit15.text:='';
   edit16.text:='';  edit17.text:='';  edit18.text:='';  edit19.text:='';
   edit20.text:='';  edit21.text:='';  edit22.text:='';  edit12.enabled:=true;
   edit13.enabled:=false;  edit14.enabled:=false;   speedbutton2.visible:=false;
   edit12.setfocus;
   adotable1.First;
   groupbox4.enabled:=true;
   radiobutton4.Checked:=true;
   while not adotable1.eof do begin
     adotable1.delete;
   end;
   end else begin
    showmessage('请将客户信息添全。');
   end;
   except
    showmessage('数据不能连接。');
   end;
  BITBTN2.Enabled:=FALSE;
end;
procedure TCPRK.BitBtn3Click(Sender: TObject);   //取消
begin
 combobox1.text:='';
 combobox1.Enabled:=true;
 adotable1.Cancel;
 bitbtn5.enabled:=false; bitbtn6.enabled:=false;  bitbtn1.enabled:=true;
 bitbtn2.enabled:=false; bitbtn3.enabled:=false;  bitbtn4.enabled:=true;
 edit12.visible:=false; edit13.visible:=false;  edit14.visible:=false;
 edit15.visible:=false; edit16.visible:=false;  edit17.visible:=false;
 edit18.visible:=false; edit19.visible:=false;  edit20.visible:=false;
 edit21.visible:=false; edit22.visible:=false; groupbox4.enabled:=true;
 groupbox4.enabled:=false;
 adotable7.open;
 adotable1.First;
 while not adotable1.eof do begin
    adotable1.delete;
    end;
 adotable9.Active:=false;
end;

#8


procedure TCPRK.BitBtn2Click(Sender: TObject);  //入库
var i:string;
begin
   try  i:='';
   If strtoint(edit2.Text) <> strtoint(edit3.Text) Then begin   //如应付与实付不符
    showmessage('实付款于应付款不符,系统将建立借贷关系。');
    adotable1.first;
    while not adotable1.eof do begin
       I:=I+'[产品名称:('+adotable1.fieldbyname('cpmc').asstring+')数量:('+adotable1.fieldbyname('shuliang').asstring+')];      ';
       adotable1.next;
    end;
    adotable8.insert;       //保存欠款到借贷表
    adotable8.fieldbyname('piao').asstring:=combobox1.text;
    adotable8.fieldbyname('jsr').asstring:=mrqp.label1.caption;
    adotable8.fieldbyname('rdate').asdatetime:=date;
    adotable8.fieldbyname('shuliang').asstring:=edit1.text;
    adotable8.fieldbyname('khbh').asstring:=edit7.text;
    adotable8.fieldbyname('khqc').asstring:=edit8.Text;
    adotable8.fieldbyname('lxdh').asstring:=edit9.text;
    adotable8.fieldbyname('ying').asinteger:=strtoint(edit2.text);
    adotable8.fieldbyname('shi').asinteger:=strtoint(edit3.text);
    adotable8.fieldbyname('huo').asstring:='入库';
    adotable8.fieldbyname('chanpin').asstring:=i;
    If strtoint(edit2.Text) < strtoint(edit3.Text) Then begin
      adotable8.fieldbyname('zhaigx').asstring:='借出';
      adotable8.fieldbyname('zhai').asinteger:=strtoint(edit3.text)-strtoint(edit2.text);
    end else begin
      adotable8.fieldbyname('zhaigx').asstring:='借入';
      adotable8.fieldbyname('zhai').asinteger:=strtoint(edit2.text)-strtoint(edit3.text);
    end;
    adotable8.post;
   end;
   adotable1.cancel;
   adotable1.First;
   while not adotable1.eof do begin
    if adotable4.Locate('cpbh',adotable1.fieldbyname('cpbh').asstring,[Lopartialkey]) then begin //查询商品
       adotable4.edit;       //库存增加
       adotable4.FieldByName('shuliang').asinteger:=adotable4.fieldbyname('shuliang').asinteger+adotable1.fieldbyname('shuliang').asinteger;
       adotable4.fieldbyname('je').asinteger:=adotable4.fieldbyname('je').asinteger+adotable1.fieldbyname('je').asinteger;
       adotable4.fieldbyname('shi').asinteger:=adotable4.fieldbyname('shi').asinteger+adotable1.fieldbyname('shi').asinteger;
       adotable4.post;
       End
     Else begin
       adotable4.InsertRecord([adotable1.fieldbyname('cpbh').asstring,adotable1.fieldbyname('cpmc').asstring,
            adotable1.fieldbyname('cpxh').asstring,adotable1.fieldbyname('cpbs').asstring,adotable1.fieldbyname('danjia').asinteger,
            adotable1.fieldbyname('dan').asstring,adotable1.fieldbyname('shuliang').asstring,adotable1.fieldbyname('cx').asstring,
            adotable1.fieldbyname('cd').asstring,adotable1.fieldbyname('pi').asstring,adotable1.fieldbyname('ling').asstring,
            adotable1.fieldbyname('jy').asstring,adotable1.fieldbyname('je').asstring,adotable1.fieldbyname('shi').asstring]);
       adotable4.post;
     end;
     adotable7.insert;  //保存入库到入库单
     adotable7.fieldbyname('piao').asstring:=combobox1.text;
     adotable7.FieldByName('cpbh').asstring:= adotable1.fieldbyname('cpbh').asstring;
     adotable7.fieldbyname('cpmc').asstring:=adotable1.fieldbyname('cpmc').asstring;
     adotable7.FieldByName('cpxh').asstring:= adotable1.fieldbyname('cpxh').asstring;
     adotable7.fieldbyname('cpbh').asstring:= adotable1.fieldbyname('cpbh').asstring;
     adotable7.fieldbyname('cpbs').asstring:= adotable1.fieldbyname('cpbs').asstring;
     adotable7.fieldbyname('danjia').asstring:= adotable1.fieldbyname('danjia').asstring;
     adotable7.fieldbyname('dan').asstring:=adotable1.fieldbyname('dan').asstring;
     adotable7.fieldbyname('cx').asstring:=adotable1.fieldbyname('cx').asstring;
     adotable7.fieldbyname('cd').asstring:=adotable1.fieldbyname('cd').asstring;
     adotable7.fieldbyname('pi').asinteger:= adotable1.fieldbyname('pi').asinteger;
     adotable7.fieldbyname('ling').asinteger:= adotable1.fieldbyname('ling').asinteger;
     adotable7.fieldbyname('jy').asinteger:=adotable1.fieldbyname('jy').asinteger;
     adotable7.FieldByName('je').asinteger:=adotable1.fieldbyname('je').asinteger;
     adotable7.fieldbyname('shi').asinteger:=adotable1.fieldbyname('shi').asinteger;
     adotable7.fieldbyname('shuliang').asstring:= adotable1.fieldbyname('shuliang').asstring;
     adotable7.fieldbyname('khbh').asstring:= adotable1.fieldbyname('khbh').asstring;
     adotable7.fieldbyname('khqc').asstring:= adotable1.fieldbyname('khqc').asstring;
     adotable7.fieldbyname('lxdh').asstring:= adotable1.fieldbyname('lxdh').asstring;
     adotable7.fieldbyname('lxr').asstring:= adotable1.fieldbyname('lxr').asstring;
     adotable7.fieldbyname('sj').asstring:= adotable1.fieldbyname('sj').asstring;
     adotable7.fieldbyname('di').asstring:= adotable1.fieldbyname('di').asstring;
     adotable7.fieldbyname('yb').asstring:= adotable1.fieldbyname('yb').asstring;
     adotable7.fieldbyname('jsr').asstring:= adotable1.fieldbyname('jsr').asstring;
     adotable7.fieldbyname('rdate').asdatetime:= adotable1.fieldbyname('rdate').asdatetime;
     adotable7.fieldbyname('shi').asinteger:= adotable1.fieldbyname('shi').asinteger;
    adotable7.post;
    adotable1.delete;
   end;
  adotable9.insert;    //增加票号到票号表
  adotable9.fieldbyname('piao').asstring:=combobox1.Text;
  combobox1.Items.add(combobox1.text);
  adotable9.Post;
  adotable9.active:=false;
  combobox1.Text:='';
  combobox1.enabled:=true;
  datasource1.DataSet:=adotable7;    //查看库存情况
  adotable7.open;
  adotable1.Cancel;
  bitbtn5.enabled:=false;
  bitbtn6.Enabled:=false;
  bitbtn1.enabled:=true;
  bitbtn2.enabled:=false;
  bitbtn3.enabled:=false;
  bitbtn4.enabled:=true;
  groupbox4.enabled:=false;
  groupbox4.enabled:=false;
 except
 showmessage('数据有误,无法入库。');
 end;
end;
procedure TCPRK.ComboBox1Click(Sender: TObject);
begin
if combobox1.text='所有记录' then begin
adotable7.filtered:=false;
end else begin
adotable7.Filtered:=true;
adotable7.filter:=format('piao'+'='+'''%s''',[combobox1.text]);
end;
end;
procedure TCPRK.BitBtn5Click(Sender: TObject);
begin
edit12.text:='';
edit13.text:='';
edit14.text:='';
edit15.text:='';
edit16.text:='';
edit17.text:='';
edit18.text:='';
edit19.text:='';
edit20.text:='';
edit21.text:='';
edit22.text:='';
edit12.setfocus;
end;
procedure TCPRK.Edit3Exit(Sender: TObject);
begin
if edit3.text='' then begin
   edit3.text:='0'
   end;
end;
procedure TCPRK.Edit7KeyPress(Sender: TObject; var Key: Char);  //利用客户编号选择客户信息
begin
 if key=#13 then begin     //回车
  if edit7.text<>'' then begin
  edit8.text:='';
  edit9.text:='';
  edit10.text:='';
  edit4.Text:='';
  edit5.text:='';
  edit6.text:='';
  if adotable2.Locate('khbh',edit7.text,[Lopartialkey]) then begin    //查找客户
   edit7.text:=adotable2.fieldbyname('khbh').asstring;     //填入客户信息
   edit8.text:=adotable2.fieldbyname('khqc').asstring;
   edit9.text:=adotable2.fieldbyname('lxdh').asstring;
   edit6.text:=adotable2.fieldbyname('lxr').asstring;
   edit5.text:=adotable2.fieldbyname('sj').asstring;
   edit4.text:=adotable2.fieldbyname('di').asstring;
   edit10.text:=adotable2.fieldbyname('yb').asstring;
  End
  Else begin
     showmessage('系统中无此编号,请添加。');
  end;
  bitbtn1.setfocus;
  end;
 end;
 if (key<'0') or (key>'9') or (key=#8)then key:=#0;
end;

#9


用id做字段名应该是没有问题的,我就经常这么做。
楼主说的不明白,没有弄懂。不过写查询语名一般是这样的:
adoquery1.Close;//先关闭query
adoQuery1.SQL.Clear; //再清空其内容
adoQuery1.SQL.Add('Delete from rklsb'); //加上查询的内容
adoQuery1.ExecSQL; //最后执行

退出此窗口时加上adoquery1.Close;也行,在ExecSQL后加恐怕要出问题。

#10


procedure TCPRK.Edit8KeyPress(Sender: TObject; var Key: Char);  //选择客户信息
begin
if edit8.text<>'' then begin
if adotable2.Locate('khqc',edit8.text,[Lopartialkey]) then begin
   edit7.text:=adotable2.fieldbyname('khbh').asstring;
   edit8.text:=adotable2.fieldbyname('khqc').asstring;
   edit9.text:=adotable2.fieldbyname('lxdh').asstring;
   edit6.text:=adotable2.fieldbyname('lxr').asstring;
   edit5.text:=adotable2.fieldbyname('sj').asstring;
   edit4.text:=adotable2.fieldbyname('di').asstring;
   edit10.text:=adotable2.fieldbyname('yb').asstring;
   End
Else begin
   showmessage('系统中无此名称,请添加。');
   end;
end;
end;
procedure TCPRK.Edit12KeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin //回车选择产品信息
 edit21.text:='';
 edit13.text:='';
 edit14.text:='';
 edit15.text:='';
 edit16.text:='';
 edit17.text:='';
 edit18.text:='';
 edit19.text:='';
 edit20.text:='';
 edit22.text:='';
 if adotable3.locate('cpbh',edit12.text,[loCaseInsensitive]) then   //查询产品信息
   begin
     edit12.text:=adotable3.fieldbyname('cpbh').asstring;
     edit13.text:=adotable3.fieldbyname('cpmc').asstring;
     edit14.text:=adotable3.fieldbyname('cpxh').asstring;
     edit16.text:=inttostr(adotable3.fieldbyname('pi').asinteger);
     edit17.text:=inttostr(adotable3.fieldbyname('ling').asinteger);
     edit18.text:=inttostr(adotable3.fieldbyname('jy').asinteger);
     a11:=adotable3.fieldbyname('dan').asstring;
     edit19.text:=inttostr(adotable3.fieldbyname('danjia').asinteger);
     a12:=adotable3.fieldbyname('cx').asstring;
     a13:=adotable3.fieldbyname('cd').asstring;
     End
 Else
     begin
     showmessage('系统中无此编号,请添加。');
     end;
 edit15.SetFocus;
 end;
end;

procedure TCPRK.Edit13KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
   if edit13.text<>'' then
        edit14.SetFocus
   Else begin
        key:=#0;
        showmessage('请输入产品名称。');
   end;
end;

procedure TCPRK.Edit14KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then begin     //回车利用产品型号选择产品
if adotable3.locate('cpmc;cpxh',vararrayof([edit13.text,edit14.text]),[loCaseInsensitive]) then
  begin
    edit12.text:=adotable3.fieldbyname('cpbh').asstring;
    edit13.text:=adotable3.fieldbyname('cpmc').asstring;
    edit14.text:=adotable3.fieldbyname('cpxh').asstring;
    edit16.text:=inttostr(adotable3.fieldbyname('pi').asinteger);
    edit17.text:=inttostr(adotable3.fieldbyname('ling').asinteger);
    edit18.text:=inttostr(adotable3.fieldbyname('jy').asinteger);
    a11:=adotable3.fieldbyname('dan').asstring;
    edit19.text:=inttostr(adotable3.fieldbyname('danjia').asinteger);
    a12:=adotable3.fieldbyname('cx').asstring;
    a12:=adotable3.fieldbyname('cd').asstring;
    edit15.setfocus;
    End
Else
    begin
    showmessage('系统中无此型号,请添加。');
    end;
 end;
end;
procedure TCPRK.Edit20KeyPress(Sender: TObject; var Key: Char);
begin
 if key=#13 then begin
  try
  if edit20.text='' then edit20.text:='0';
  edit21.text:=inttostr(strtoint(edit20.text)* strtoint(edit19.text)); //计算应付金额
  edit22.Text:=edit21.text;   //实付金额
  //table1.fieldbyname('shi').asinteger:=table1.fieldbyname('je').asinteger;
  edit22.setfocus;
  except
  showmessage('不能运算!');
  end;
 end;
end;
procedure TCPRK.Edit22KeyPress(Sender: TObject; var Key: Char); //回车焦点Button1
begin
  if key=#13 then begin
  Button1.SetFocus ;
end;
end;
procedure TCPRK.Edit19KeyPress(Sender: TObject; var Key: Char);  //比较价格
var add:integer;
begin
 if key=#13 then begin
  try
  adotable6.Refresh;
  adotable6.Filtered:=true;
  adotable6.filter:=format('cpmc'+'='+'''%s''',[edit13.text]);
  if adotable6.Locate('cpmc',edit13.text,[Lopartialkey]) //查询商品
   then begin
   adotable6.last;
   add:=adotable6.fieldbyname('danjia').asinteger; end
   Else begin
    add:=adotable3.fieldbyname('danjia').asinteger; end ;
  if strtoint(edit19.text)>add then begin        //比较进价
     showmessage('本次进货价高于上次,请三思后保存。');
     end;
  edit20.setfocus;
  except on exception do showmessage('数据无法计算,请核实。');
  end;
 end;
end;
procedure TCPRK.Button1Click(Sender: TObject);  // 保存数据到临时表
begin
 try
 adotable1.open;
 adotable1.AppendRecord([edit12.text,edit13.text,edit14.text,edit15.text,
       mrqp.label1.caption,date,edit19.text,a11,edit20.text,a12,a13,
       edit7.text,edit8.text,edit4.text,edit9.text,edit6.text,edit5.text,
       edit10.text,strtoint(edit16.text),strtoint(edit17.text),strtoint(edit18.text),
       strtoint(edit21.text),strtoint(edit21.text),strtoint(edit22.text)]);
  edit1.text:=inttostr(strtoint(edit1.text)+strtoint(edit20.text));
  edit2.text:=inttostr(strtoint(edit2.text)+strtoint(edit21.text));
  edit3.text:=inttostr(strtoint(edit3.text)+strtoint(edit22.text));
  edit12.text:=''; edit13.text:=''; edit14.text:='';edit15.text:='';
 edit16.text:='';edit17.text:=''; edit18.text:=''; edit19.text:='';
 edit20.text:='';edit21.text:=''; edit22.text:='';
 if radiobutton4.Checked then edit12.setfocus;
 if radiobutton5.checked then edit13.setfocus;
 if radiobutton6.checked then bitbtn2.setfocus;
 BITBTN2.Enabled:=TRUE;

 except
 showmessage('输入格式错误。');
 end;
end;
procedure TCPRK.BitBtn4Click(Sender: TObject);   //退出
begin
 close;
end;
end.

#11


引用 9 楼 wjs_002 的回复:
用id做字段名应该是没有问题的,我就经常这么做。
楼主说的不明白,没有弄懂。不过写查询语名一般是这样的:
adoquery1.Close;//先关闭query
adoQuery1.SQL.Clear; //再清空其内容
adoQuery1.SQL.Add('Delete from rklsb'); //加上查询的内容
adoQuery1.ExecSQL; //最后执行

退出此窗口时加上adoquery1.Close;也行,在ExecSQL后加恐怕要出问题。


我也觉得问题不是出在这里,可是我找不出问题,于是就描述不清
你的方法试过了没用

#12


自动编号列删除,试试看!要不就不要用自动编号!自己编号!

#13


id是自动编号的吧。。。。既然设置了自动编号,那代码中就不要再id:=id+1了。。。。

或者就把数据库里id别设为自动编号

二选一