Results 1 to 8 of 8
  1. #1

    Display DB result set problem

    Hi all,
    please first find the following code.
    DB Connection
    Public Sub DBConnect()
    Set Res=createobject("ADODB.Recordset")
    Set Cmd=createobject("ADODB.Command")
    StrCon= "Provider=MSDASQL.1;Password=***;Persist Security Info=True;User ID=***;Data Source=***"
    Cmd.CommandType = 1
    End Sub
    SQL Execute
    Public Sub ExecuteSql(StrSql)
    Set Res = Cmd.Execute()
    End Sub
    In my QTP test case code, i use the following code to display the Query result set. But the result display nothing, it seems the Res.EOF value is always True. The Loop section is never executed.
    ExecuteSql("select a.BEGIN_DATE from HISTORY a where a.DEVICE_ID='******' order by a.BEGIN_DATE")
    Do While Not Res.EOF
    print Res("BEGIN_DATE")
    Please help me find out why? Thanks.

  2. #2

    Re: Display DB result set problem

    Run the same query on some other SQL client and see if returns any rows or not? ALso make sure you are connecting to the correct database.

  3. #3

    Re: Display DB result set problem

    I run the same query, and can return the right result.
    And I am sure the DBConnection is right.Because in same test case, there are other query can be executed successfully.The difference is that the successfully query result only includes one value.The unsuccessfully query includes one result set.

  4. #4

    Re: Display DB result set problem

    Does anybody here meet this similar problem?

  5. #5

    Re: Display DB result set problem

    Do on thing. Use a function to convert the date to a string format. In SQL you can use TO_CHAR. In case some other DB then just look at the specific DB function

  6. #6

    Re: Display DB result set problem

    I try your advice. It works. The Res.EOF is not False any more.

    But when QTP run "print Res("BEGIN_DATE")", it raises the "General Run error", and maybe this is not the right way to see the query result set. I tried import the result set to datatable,it failed also.
    Could you please tell me how to display the result set correctly? Thanks.

  7. #7

    Re: Display DB result set problem

    Try this and see if it work

    print Res(0).Value

    Post the query you are using in case it is not working.

  8. #8

    Re: Display DB result set problem

    It works thanks to your advice. Sorry for the late response.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
BetaSoft Inc.
All times are GMT -8. The time now is 05:52 PM.

Copyright BetaSoft Inc.