Forum Discussion

albertopasion's avatar
albertopasion
Occasional Contributor
14 years ago

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;

  • albertopasion's avatar
    albertopasion
    Occasional Contributor

    Nope. I did not use Double Quotes in my code.


    TESTCOMPLETE example for DelphiScript using ADO createparameter does not work with MicroSoft SQL server 2008.


    There has to be a different way of declaring parameters in the commandtext.



  • Hi Albert,





    Have you tried the following suggestions provided in the article mentioned above:

    Execute the connection level option SET QUOTED_IDENTIFIER OFF immediately after establishing the connection with the database.





    If you are using the Microsoft OLEDB Provider for ODBC Drivers, you can add the following to the end of you connection string: 'QuotedID=No'