Lazarus 将 sql 结果提交给 dbedit

Lazarus get sql result to dbedit

我需要在 Lazarus 中获取 select 语句的结果并将此结果分配给 edit.text。

代码:

procedure TForm1.Button1Click(Sender: TObject);

var
  Q: TSQLQuery;
  d: string;
begin
  //Q := TSQLQuery.Create(nil);

  with OracleConnection1 do
  begin
    Connected := true;
    SQLTransaction1.Active:= True;

    DataSource1.Enabled:=true;
    DataSource1.DataSet := Q;
  end;
  if OracleConnection1.Connected then

   Q.SQL.Text := 'SELECT description FROM part where part= "00000" ';
   Q.Active:=true;
   Q.ExecSQL;
   d := datasource1.DataSet;
   //DBText1.ExecuteAction();
   dbedit1.Text:= q.DataSource.DataSet.Fields.;

   Edit1.Text:= Q.SQL.Text;
   showmessage('CONNECTED');
   sql.Active:=true;
end;    

您的代码中有不少错误。您可能应该在某个地方找到关于 Delphi 的教程(这与 Lazarus 和 FreePascal 非常相似)。

procedure TForm1.Button1Click(Sender: TObject);
var
  Qry: TSQLQuery;
begin
  Qry := TSQLQuery.Create(nil);
  with OracleConnection1 do
  begin
    Connected := true;
    SQLTransaction1.Active:= True;
    DataSource1.Enabled:=true;
    DataSource1.DataSet := Q;
  end;
  if OracleConnection1.Connected then
  begin
   showmessage('CONNECTED');
   Qry.SQL.Text := 'SELECT description FROM part where part= "00000" ';
   Qry.Open; 

   Edit1.Text:= Qry.FieldByName('description').AsString;
end;