Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing items returned from a SQL query

Status
Not open for further replies.

rhysmeister

Programmer
May 29, 2003
54
GB
I am using Delphi to access a SQl server DB. Just having a little trouble accessing the results from a SQL statement (which appears to run well). I want to put them onto a label on a form. Here is my code so far...

Code:
Close; // Close any present DB connection
SQL.Clear;
SQL.Add('SELECT * FROM ACI_Errors WHERE ID = (:SelectedParam)');
// Get the index of selected row adding 1
ParamByName('SelectedParam').AsInteger := DBGrid1.SelectedIndex + 1;
ExecSQL; // Execute the SQL
 
ok... then continue with
Code:
Open;
First;
while not eof do
begin
  Label1.Text := Label1.Text + ', ' + FieldByName('field_name_to_display').AsString;
  Next;
end;
Close;

ofc this code is just a simple example and that you need to change it to suit your needs, but at least will give you a start
 
remove the ExecSQL() statement

ok... then continue with
Code:
Open;
First;
while not eof do
begin
  Label1.Text := Label1.Text + ', ' + FieldByName('field_name_to_display').AsString;
  Next;
end;
Close;

ofc this code is just a simple example and that you need to change it to suit your needs, but at least will give you a start
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top