在程序运行时,向表里面插入,或者修改表里面的信息会出错,弹出来的信息见附件文件。麻烦解决!
谢谢!

解决方案 »

  1.   

    看”cgdbh“是否有这个参数,一般是你在为一个不存在的参数赋值
      

  2.   

    ADOQuery1得参数没有找到。看一下‘cgdbh’是不是和数据库中的字段名称不一致?
      

  3.   

    unit Purchase;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, DB, ADODB, ExtCtrls;type
      TForm4 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Edit1: TEdit;
        Edit2: TEdit;
        Edit3: TEdit;
        Edit4: TEdit;
        Edit5: TEdit;
        Bevel1: TBevel;
        Button1: TButton;
        Button2: TButton;
        ADOQuery1: TADOQuery;
        procedure Button2Click(Sender: TObject);
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form4: TForm4;implementationuses PurchaseInfo, DataModule;{$R *.dfm}procedure TForm4.Button2Click(Sender: TObject);
    begin
       form4.Close;
    end;procedure TForm4.Button1Click(Sender: TObject);
    var
      str:string;
    begin
      if edit1.Text='' then
      begin
        showmessage('请输入采购单编号');
        edit1.SetFocus;
        exit;
      end;
      if edit2.Text='' then
      begin
        showmessage('请输入商品编号');
        edit1.SetFocus;
        exit;
      end;
      if edit3.Text='' then
      begin
        showmessage('请输入进货价');
        edit1.SetFocus;
        exit;
      end;
      if edit4.Text='' then
      begin
        showmessage('请输入进货数量');
        edit1.SetFocus;
        exit;
      end;
      if edit5.Text='' then
      begin
        showmessage('请输入进货日期');
        edit1.SetFocus;
        exit;
      end;
      adoquery1.Close;
      adoquery1.SQL.Clear;
      if form5.Tag=1 then
      begin
        adoquery1.SQL.Add('select * from Purchase where 采购单编号=:cgdbh');
        adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
        adoquery1.Open;
        if adoquery1.RecordCount>0 then
        begin
          showmessage('采购单编号已存在,请重新输入');
          edit1.Text:='';
          edit1.SetFocus;
          exit;
        end;
        adoquery1.Close;
        adoquery1.SQL.Clear;
        adoquery1.SQL.Add('insert into Purchase');
        adoquery1.SQL.Add('values(:cgdbh,:spbh,:jhj,:jhsl,:jhrq)');
      end;
      if form5.Tag=2 then
      begin
        str:=edit1.Text;
        adoquery1.Close;
        adoquery1.SQL.Clear;
        adoquery1.SQL.Add('update Purchase set 采购单编号=:cgdbh,商品编号=:spbh,'
                     +'进货价=:jhj,进货数量=:jhsl,进货日期=:jhrq'
                     +' where 采购单编号=:oldcgdbh');
       adoquery1.Parameters.ParamByName('oldcgdbh').Value:=str;
      end;
      form5.ADOQuery1.Close;
      adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
      adoquery1.Parameters.ParamByName('spbh').Value:=edit2.Text;
      adoquery1.Parameters.ParamByName('jhj').Value:=edit3.Text;
      adoquery1.Parameters.ParamByName('jhsl').Value:=edit4.Text;
      adoquery1.Parameters.ParamByName('jhrq').Value:=edit5.Text;
      adoquery1.ExecSQL;
      form5.ADOQuery1.Open;
      close;
    end;
    这是代码
      

  4.   

    adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text; 
      

  5.   

    if form5.Tag=1 then 
      begin 
        adoquery1.SQL.Add('select * from Purchase where 采购单编号=:cgdbh'); 
        adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text; 
        adoquery1.Open; 
        if adoquery1.RecordCount> 0 then 
        begin 
          showmessage('采购单编号已存在,请重新输入'); 
          edit1.Text:=''; 
          edit1.SetFocus; 
          exit; 
        end; 
        
      end; 
      if form5.Tag=2 then 
      begin 
        str:=edit1.Text; 
        adoquery1.Close; 
        adoquery1.SQL.Clear; 
        adoquery1.SQL.Add('update Purchase set 采购单编号=:cgdbh,商品编号=:spbh,' 
                     +'进货价=:jhj,进货数量=:jhsl,进货日期=:jhrq' 
                     +' where 采购单编号=:oldcgdbh'); 
       adoquery1.Parameters.ParamByName('oldcgdbh').Value:=str; 
       
      adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text; 
      adoquery1.Parameters.ParamByName('spbh').Value:=edit2.Text; 
      adoquery1.Parameters.ParamByName('jhj').Value:=edit3.Text; 
      adoquery1.Parameters.ParamByName('jhsl').Value:=edit4.Text; 
      adoquery1.Parameters.ParamByName('jhrq').Value:=edit5.Text; 
      adoquery1.ExecSQL; 
     end;
      

  6.   

    在adoquery1.Close;后加入adoquery1.Parameters.Clear;
    没重新操作都要执行
    adoquery1.Close;
    adoquery1.SQL.Clear;
    adoquery1.Parameters.Clear;