Forum Discussion

sguda's avatar
sguda
Regular Contributor
13 years ago

I need retrieve the database record through scripting with variable value

Hi

I am accessing the database and trying to retrieve the record with primary key matching the variable value. When i give the direct value instead of Variable i am able to retrieve. But when i am using variable i am getting error. So please suggest me where i am doing wrong. I am trying to use variable for SSN values


Sub Delete_Eligibilty_Records


Delete_Eligibilty_Records

   Dim Eligibilty_ID ,Award_Year, Eligibilty_Details_ID, Stud_Id , Stud_SSN


   Stud_SSN = 594823868


 


 


   Set aCon1 = ADO.CreateADOConnection




 


  aCon1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Eligibility"


 


  aCon1.LoginPrompt = False


 


  aCon1.Open


 


  Set Recset4 = aCon1.Execute_("select IDStudent from Student where (SSN = Stud_SSN) ")


  RecSet4.MoveFirst


 While Not RecSet4.EOF


     If RecSet4.Fields("IDStudent").Value > "" Then


     Log.Message RecSet4.Fields("IDStudent").Value


    Stud_Id = RecSet4.Fields("IDStudent").Value


    Log.Message Stud_Id 


 End If


RecSet4.MoveNext


Wend

6 Replies

  • Hi,



    You should use the value stored in your variable, not its name.

    Set Recset4 = aCon1.Execute_("select IDStudent from Student where (SSN = " & Stud_SSN & ") ")

  • sguda's avatar
    sguda
    Regular Contributor
    Hi,



    I tried with that syntax that has been given, i was getting the error as attached.


  • Hi,



    An integer value is expected to be passed in your query. The passed one (TP075 St) is not an integer value. Debug your script and make sure that the correct values are passed on each step.
  • sguda's avatar
    sguda
    Regular Contributor
    Hi Jared,

    As you can see in the code of the script routine, I declared the Stud_SSN variable locally as DIM Stud_SSN.

    I don't understand how i can declare values locally as integers and doubles and boolean etc. when i tried, i am getting error.

    I waat to define the variables as public and different type instead of only string type.

    So when i define locally as dim Stud_SSN it is treating it as string.

    I defined variable in the project permamant variable and used in the script as follows and still getting the same kind of error.



     

    Sub Delete_Eligibilty_Records


    Delete_Eligibilty_Records

     


    Set aCon1 = ADO.CreateADOConnection


     


    aCon1.ConnectionString = "Provider=MSDASQL.1;Persist Security Info=False;Data Source=Eligibility"


     


    aCon1.LoginPrompt = False


     


    aCon1.Open


     


    '****Retrieves the Student ID record from Stdent table


     


    'Set Recset4 = aCon1.Execute_("select IDStudent from Student where (SSN = 594118868)")


    Set Recset4 = aCon1.Execute_("select IDStudent from Student where (SSN = " & PROJECT.Variables.Stud_SSN & ") ")


    RecSet4.MoveFirst


    While Not RecSet4.EOF


    If RecSet4.Fields("IDStudent").Value > "" Then


    Log.Message RecSet4.Fields("IDStudent").Value


    Stud_Id = RecSet4.Fields("IDStudent").Value


    Log.Message Stud_Id


    End If


    RecSet4.MoveNext


    Wend



    I tried defining locally as string and converting to string and still getting the same error as attched .



    So help me with this.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    The error you posted is coming from the SQL server, not from the TestComplete code.



    What I've seen in that case is that, for some reason or another, the database that you are querying has incorrect data in the column in question.  It almost looks like the SSN volumn in your database is containing values that are non-integer.  Check your data integrity of your SQL database and makes sure you don't have some sort of strange mis match.