如全部这样写比较麻烦:
DataModule1.ADOtablejbqk.FieldByName('xm').AsString:=edit1.Text;
 DataModule1.ADOtablejbqk.FieldByName('cym').AsString:=edit2.Text;

解决方案 »

  1.   

    procedure TForm1.Button2Click(Sender: TObject);
    var
      i: Integer;
    begin
      for i := 1 to 3do
        DataModule1.ADOtablejbqk.fields[i].value :=
            TEdit(FindComponent('Edit' + IntToStr(i))).Text);
    end;
      

  2.   

    可以写个录入函数吗!在edit编辑框录入完成以后,调用函数不就可以了!哈哈
      

  3.   

    用dbedit,用cds,直接就post了。
      

  4.   

    用dbedit,邦盯数据原,用字段=:字段的方法很简单,很好
      

  5.   

    问题是这样:form中有更多的控件如还有combobox控件,date控件,而且不是与数据中字段相对应的,meiqingsong的循环这样处理也就不行了,如用adocommand控件来做,如何做?
      

  6.   

    用TAG对控件进行编号。
    把COMBOBOX和EDIT的名字都设置为edit+tag,例如tag为1的edit就是edit1,tag为2的combobox就是EDIT2,
    设置的tag值对应数据库的fields号。
    for i := 1 to 3do
        DataModule1.ADOtablejbqk.fields[i].value :=
            TEdit(FindComponent('Edit' + IntToStr(i))).Text);
    这个循环就可以用了,不用担心COMBOBOX的转换,
    最后再对date控件赋值。
      

  7.   

    我的方法是用edit的name做判断,就是name+编号,比如edit001
    procedure Tshuidianqi.BitBtn1Click(Sender: TObject);
    var
      i:integer;sqltext:string;
    begin
    ////////////// 确定去那一天的数据,先把时间弄成字符串,
      try
      begin
      lururq:='a'+copy(FormatDateTime('yyyymmdd',findtime.date),7,2);
    ////////////////////////////
      for i:=0 to ComponentCount-1 do
          if Components[i] is TEdit then
            if   trim(TEdit(Components[i]).Text)<>'' then
            begin
              //showmessage(copy(TEdit(Components[i]).Name,5,6));    //showmessage(TEdit(Components[i]).Text)
           sqltext:='update dd_tz set '+lururq+'='+TEdit(Components[i]).Text+'  where dm='+''''+copy(TEdit(Components[i]).Name,5,6)+''''+'  and rq='+copy(FormatDateTime('yyyymmdd',findtime.date),1,6);          with adoquery1 do
                   begin
                     close;
                     sql.Clear;
                    // sql.Add('update dd_tz set '+lururq+'='+TEdit(Components[i]).Text+'where dm='+''''+copy(TEdit(Components[i]).Name,5,6)+''''+'  and rq='+copy(FormatDateTime('yyyymmdd',findtime.date),1,6));
                    sql.Text:=sqltext;
                   execsql;
                  end;          end;
         end;
        showmessage(FormatDateTime('yyyy-mm-dd',findtime.Date)+'号水电汽数据已成功存盘!');        except
            showmessage('操作错误,数据未存盘!请重试!')
            
    end;
    end;