This example uses SqlServer
The first way the result in the Memo control ,, need to refer to SynCommons, SynDB, SynOleDb;
procedure TForm1.Button1Click(Sender: TObject); var DbConn: TOleDBMSSQLConnectionProperties; strSql: string; rows: ISQLDBRows;begin DbConn := TOleDBMSSQLConnectionProperties.Create('127.0.0.1', 'ReportServer', 'sa', 'Sa123'); strSql := 'SELECT r.RoleName, r.Description FROM Roles AS r'; rows := DbConn.ExecuteInlined(strSql, True); if rows <> nil then begin memo1.Clear; memo1.Lines.BeginUpdate;
while rows.Step() do begin Memo1.Lines.Add(rows.ColumnString('RoleName') + '-' + rows.ColumnString('Description')); end; end; Memo1.Lines.EndUpdate; end;
The second way to return the data set to the DBGrid control, you need to referenceSynCommons, SynDB, SynOleDb, SynDBMidasVCL;
procedure TForm1.Button2Click(Sender: TObject); var DbConn: TOleDBMSSQLConnectionProperties; ds: TSynDBDataSet; begin DbConn := TOleDBMSSQLConnectionProperties.Create('127.0.0.1', 'ReportServer', 'sa', 'Sa123'); ds := TSynDBDataSet.Create(nil); ds.Connection := DbConn; ds.CommandText := 'SELECT r.RoleName, r.Description FROM Roles AS r' ; Ds.Open; DataSource1.DataSet: = DS; // DS can not be otherwise released here results not shown End ;
The results of two ways