ADO createparameter - TestComplete sample DelphiScript
I have this simple code below. It basically connects to a DB and tries to execute a SQL statement with one parameter (MyParam). I tried following one of you Delphi Script examples but I am getting an SQL error stating that I have an invalid column name "MyParam".
Please see attached.
Is there a more update example for doing this?
Thanks in advance.
Albert
===========================================
procedure TestADOSelect;
var
AConnection, RecSet, Cmd, Prm : OleVariant;
begin
ADOConnect(AConnection);
try
// Create a new Command object
Cmd := ADO.CreateCommand;
// Specify the connection
Cmd.ActiveConnection := AConnection;
// Specify command type and text
Cmd.CommandText := 'Select * from SIBInvoices where Organization_Id = MyParam';
Cmd.CommandType := adCmdText;
// Create a new parameter
Prm := Cmd.CreateParameter('MyParam', adInteger, adParamInput);
Cmd.Parameters.Append(Prm);
// Specify the parameter value
Prm.Size := 5;
Prm.Value := 99274;
// Execute the command
RecSet := Cmd.Execute;
// Process the results
RecSet.MoveFirst;
while not aqConvert.VarToBool(RecSet.EOF) do
RecSet.MoveNext;
finally
AConnection.Close;
end;
end;
procedure ADOConnect(var AConnection: OleVariant);
begin
// Create a new Connection object
AConnection := ADO.CreateConnection;
// Specify the connection string
Connection.ConnectionString := 'Provider=SQLOLEDB.1;' +
'Password=password;' +
'Persist Security Info=True;' +
'User ID=sa;' +
'Initial Catalog=TEST;' +
Data Source=DEVSERV';
AConnection.Open;
end;