Try this out:
procedure TForm2.Button1Click(Sender: TObject);
begin
try
Connect;
SQLMonitor1.SQLConnection := SQLConnection1;
SQLMonitor1.Active := True;
ExecuteQueries;
SQLMonitor1.SaveToFile('D:\Log.txt');
except
on E: Exception do
ShowMessage('Exception ocurred!: ' + E.Message);
end;
end;
procedure TForm2.Connect;
begin
SQLConnection1 := TSQLConnection.Create(nil);
SQLConnection1.ConnectionName := 'odbcinterbaseconnection';
SQLConnection1.LoginPrompt := False;
SQLConnection1.LoadParamsOnConnect := True;
SQLConnection1.Connected := True;
end;
procedure TForm2.ExecuteQueries;
var
Query: String;
begin
try
if SQLConnection1.Connected then
begin
Query := 'CREATE TABLE ExampleTable(id INTEGER, name VARCHAR(50))';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(1,''test1'')';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(2,''test2'')';
SQLConnection1.Execute(Query, nil);
Query := 'INSERT INTO ExampleTable VALUES(3,''test3'')';
SQLConnection1.Execute(Query, nil);
Query := 'SELECT * FROM ExampleTable';
SQLConnection1.Execute(Query, nil);
end;
except
on E: Exception do
ShowMessage('Exception ocurred!: ' + E.Message);
end;
end;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…