Hi all,
I am trying to use ADOQuery but program crashes when it tries to
execute this line:
ADOQuery1.Connection := ADOConnection1;
Does anyone know why?
The following code works fine:
procedure TForm1.Button1Click(Sender: TObject);
var
RS: _RecordSet;
begin
ADOConnection1.ConnectionString :='Provider=SQLOLEDB.1;Integrated
Security=SSPI;Persist Security Info=False;Data Source=MYSource;Initial
Catalog=MyDB;';
ADOConnection1.Open;
RS := ADOConnection1.Execute('select * from myTable', cmdText);
end;
but when I try to use ADOQuery like this:
function TForm1.GetDetails: boolean;
var
MyADOQuery1: TADOQuery;
ListItem : TListItem;
begin
MyADOQuery1.Connection := ADOConnection1;{it crashes here}
ShowMessage('After adding ADOConnection1');
MyADOQuery1.Close;
MyADOQuery1.SQL.Clear;
MyADOQuery1.SQL.Add('select * from myTable');
MyADOQuery1.SQL.Add('where myField = :bkr');
ShowMessage(Edit1.Text);
MyADOQuery1.Parameters.Parambyname('bkr').Value := Edit1.Text;
MyADOQuery1.Open;
if (not MyADOQuery1.IsEmpty) then
begin
while (not MyADOQuery1.eof) do
begin
ListItem := lstArchiveResult.Items.Add;
ListItem.Caption :=
MyADOQuery1.fieldbyname('myField').AsString;
MyADOQuery1.Next;
end;
end;
Except on E:Exception do
begin
Showmessage('Erreur' + E.Message);
end;
end;
end;
end;
Why is it cra****ng?
Thanks,
Alan.