Forum Discussion

blearyeye's avatar
blearyeye
Contributor
14 years ago

Using ParamByName with ADO.CreateAdoStoredProc()

I have a TC function that uses an SQL server stored procedure; see below. It bombs on the ParamByName line. I've tried the name with and without the @. When I omit the line, it complains (correctly) that a value was not provided for InstanceNumber. Any ideas?



The error message is: An exception occurred in the "GetMachineConfiguration" unit at line
12: Parameter '@InstanceNumber' not found




The TC function:




function GetMachineConfiguration(instanceNumber) {


  var qry = ADO.CreateADOStoredProc();


  qry.ConnectionString = ConnectionString.ConnectionString();


  qry.ProcedureName = "dbo.STUV_GetMachineConfiguration"


  qry.Parameters.ParamByName("@InstanceNumber").Value = instanceNumber;  


  qry.Open();


  qry.First();


return qry;


}




The SQL server stored procedure:




ALTER PROCEDURE [dbo].[STUV_GetMachineConfiguration]


(


@InstanceNumber AS INT


)


AS


BEGIN


-- SET NOCOUNT ON added to prevent extra result sets from


-- interfering with SELECT statements.


SET NOCOUNT ON;


SELECT *


FROM MachineData 


INNER JOIN MachineTypes ON MachineData.MachineTypeCode = MachineTypes.MachineTypeCode


INNER JOIN MachineConfigs ON 


MachineData.MachineTypeCode = MachineConfigs.MachineTypeCode AND


MachineData.MachineLampingCode = MachineConfigs.MachineLampingCode


CROSS JOIN SoftwareData


WHERE MachineData.InstanceNumber = @InstanceNumber


END



7 Replies

  • Hello Bill,




    You need to create a parameter to work with. For example:





    function Test_GetMachineConfiguration(instanceNumber) { 


      var qry = ADO.CreateADOStoredProc(); 


      qry.ConnectionString = ConnectionString.ConnectionString(); 


      qry.ProcedureName = "dbo.STUV_GetMachineConfiguration";


      qry.Parameters.CreateParameter("return_value", adInteger, adParamReturnValue, 0, null);


      qry.Parameters.CreateParameter("InstanceNumber", adInteger, adParamInput, 0, instanceNumber);        

      qry.ExecProc();                                                                             


      return qry.Parameters.ParamByName("return_value").Value;     


    }







    Please see the Call an SQL Stored Procedure article for more information.
  • Ah, of course. But I don't see where this use of CreateParameter is documented. Can you give a pointer?



     
    qry.Parameters.CreateParameter("InstanceNumber", adInteger,
    adParamInput, 0, instanceNumber)       


  • AlexKaras's avatar
    AlexKaras
    Community Hero
    Hi Bill,



    CreateParameter is one of the methods of ADO by Microsoft that is just wrapped and accessible from TestComplete, thus you should search MSDN for ADO documentation.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The ADO object mentioned in that document is a wrapper object that TestComplete makes around the MS objects.  The specifics and tricks and such of those MS objects are documented by the MSDN site.
  • Right, I got that. But why would it be so hard to give a pointer? It's really not clear where TC-specific stuff ends and 3rd party stuff begins. Telling me (a) that I need to look elsewhere and (b) where to go look shouldn't be that big a deal.