有四个组件Edit DBGrid Button Query
当单击DBGrid中一行时,其中数据会显示在Edit中。然后修改Edit中内容,再击Button执行修改,请问Query中的SQL语句应该怎么写?

解决方案 »

  1.   

    用数据敏感控件多好啊,DBEDIT
      

  2.   

    1)在Query1的AfterScroll事件中写下述程序,这样Edit1.text中的值,
      可随DBGrid的行变化自動的变化
    procedure TDataModule1M.Query1AfterScroll(DataSet: TDataSet);
    begin
      with From1,Query1 do
      begin
        Edit1.text := FieldByName('Field1').AsString;
        {...}
      end;
    end;2)Update SQL
    UPDATE yourTable
       SET Field1=:Field1_Var
    WHERE 条件或用:Edit {...} Post
      

  3.   

    List_Query.Edit;
    List_Query.fieldByName('aa).AsString:=edit1.text;
    List_Query.fieldByName('bb).AsString:=edit2.text;
    List_Query.post;
      

  4.   

    Query.parambyname('yourfield').value:=Edit1.text;
    ........
    messowbox(handle,'记录修改成功!','修改记录',MB_OK OR MB_ICONWORING)
      

  5.   

    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('update Diary set diarydate=:diarydate,synopsis=:synopsis,content=:content where diarydate=BeforeDiarydate');
    ADOQuery1.Parameters.ParamByName('diarydate').Value:=DateTimePicker1.DateTime;
    ADOQuery1.Parameters.ParamByName('synopsis').Value:=Edit2.Text;
    ADOQuery1.Parameters.ParamByName('content').Value:=Memo1.Text;
    Showmessage(ADOQuery1.SQL.text);
    ADOQuery1.ExecSQL;请问这一段有什么问题?
    运行时报错:参数不足,期待是4
    请各位兄弟帮忙看看。
      

  6.   

    where diarydate=BeforeDiarydate 这个参数没设吧
      

  7.   

    ADOQuery1.SQL.Add('update Diary set diarydate=:diarydate,synopsis=:synopsis,content=:content where diarydate=:BeforeDiarydate');where条件也要加条件参数、
    {...}
    ADOQuery1.Parameters.ParamByName('BeforeDiarydate').Value:=...;