小弟定义了一方法,想从edit1.text,edit2.text,edit3.text值入参数值.却出现"...列值无效"的错误。要是先给ADOQuery写入sql语句再在程序中赋值的方法,则也报错,说找不到参数等。程序如下,请各位帮忙看看,小弟弄了好久,着实弄不出来啊。
procedure cat(name1,name2,money:String);
  var
    str:String;
begin
str:='update xsm2 set money=money-'+money+' where name= '+name1+' ';
str:=str+' update xsm2 set money=money+'+money+' where name= '+name2+'';
  showmessage(str);
  with form1.ADOconnection1 do
    begin
      try
        begintrans;
            with form1.ADOQuery2 do
              begin
               close;
               sql.clear;
               sql.add(str);
               prepared:=true;
               execsql;
               showmessage('事务执行成功!');
               committrans;
              end;
     except
          showmessage('事务执行失败!');
          rollbacktrans;
        end;
      end;
end;

解决方案 »

  1.   

    知道了,今天下午才发现的。可是,如果用fieldbyname('...')来赋值的话,我还是不会,编译报错说找不到参数,楼上的能不能给我用fieldbyname方法访问的代码?
      

  2.   

    try
            adotable1.Append;
            adotable1.FieldByName('ZLFBH').AsString := '';              
            adotable1.FieldByName('BJ').AsInteger := 1;    //BJ=1表示住院
            adotable1.FieldByName('MZBH').AsString := edit1.Text;
            adotable1.FieldByName('YSPYM').AsString := edit2.Text;
            adotable1.FieldByName('CZYPYM').AsString := edit3.Text;
            adotable1.FieldByName('RQ').AsString := datetostr(datetimepicker1.Date);
            adotable1.FieldByName('YPPYM').AsString := edit4.Text;
            adotable1.FieldByName('YPMC').AsString := LABEL18.Caption;
            adotable1.FieldByName('YPLX').AsString := LABEL28.Caption;
            adotable1.FieldByName('JG').AsString := LABEL24.Caption;
            adotable1.FieldByName('SL').AsString := edit6.Text;
            adotable1.Post;
        except
            SHOWMESSAGE('错误:向数据库添加数据失败(住院部电子药方)!');
            EXIT;
        end;
      

  3.   

    FieldByName('...')中是数据表的字段名
    可以用不同的类型
    asinteger
    asfloat
    asboolean  等还可以判断该字段值是否为空 FieldByName('...').isnull
      

  4.   

    这个我也知道的.我是先向组件中输入sql语句,然后再在程序中赋值,可是编译错误说找不到参数,或者就是什么列名无效啊.