SPONSORS:






User Tag List

Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Jul 2006
    Location
    China
    Posts
    70
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    problem about result of a dll

    Hi All:
    I've create a dll file the code is as follow.
    ################################################## #
    ## function for search record ######
    ## this dll return a recordset for sql search #####
    ################################################## #
    Public Function ConnectString() _
    As String
    'returns a DB ConnectString
    ConnectString = "Provider=SQLOLEDB.1;Password=kinghawk;Persist Security Info=True;User ID=sa;Initial Catalog=Personnel;Data Source=YUPENG"
    End Function
    Public Function ExecuteSQL(SQL _
    As String, MsgString As String) _
    As ADODB.Recordset
    'executes SQL and returns Recordset
    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset
    Dim sTokens() As String

    On Error GoTo ExecuteSQL_Error

    sTokens = Split(SQL)
    Set cnn = New ADODB.Connection
    cnn.Open ConnectString
    If InStr("INSERT,DELETE,UPDATE", _
    UCase$(sTokens(0))) Then
    cnn.Execute SQL
    MsgString = sTokens(0) & _
    " query successful"
    Else
    Set rst = New ADODB.Recordset
    rst.Open Trim$(SQL), cnn, _
    adOpenKeyset, _
    adLockOptimistic
    'rst.MoveLast 'get RecordCount
    Set ExecuteSQL = rst
    MsgString = "search" & rst.RecordCount & _
    " record "
    End If
    ExecuteSQL_Exit:
    Set rst = Nothing
    Set cnn = Nothing
    Exit Function

    ExecuteSQL_Error:
    MsgString = "search error: " & _
    Err.Description
    Resume ExecuteSQL_Exit
    End Function
    ################################################## #
    what I want is that every time I call this dll file and give a SQL string as a parameter. it can search the database and return the result as a recordset.so that I can use in QTP. But I use createobject("").It can't work.
    Who have some idea about this situation please let me know
    thank you in advance.
    Hello,everyone.

  2. #2
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: problem about result of a dll

    Did you create the DLL in VB6? If yes then you need to put code in a class and then compile the DLL. The CreateObject would have the Class Name as VBProjectName.ClassName and then you can use it with QTP...

  3. #3
    Member
    Join Date
    Jul 2006
    Location
    China
    Posts
    70
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: problem about result of a dll

    thank you Tarun. I'm alread to do so,but it doesn't work.
    '#######################################
    Dim e,rst,b
    Set e=createobject("project1.class1")
    Set rst =createobject("adodb.recordset")
    str="select * from table1"
    set rst=e.ExecuteSQL(str,b)
    '######################################
    I just want get the recordset of a database,so that I can compare the search result in my action. Who have better soultion about this. Please let me know.
    Hello,everyone.

  4. #4
    Member
    Join Date
    Jul 2006
    Location
    China
    Posts
    70
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Total Downloaded
    0

    Re: problem about result of a dll

    Finally ,I solve this problem. I must add ADO 2.X reference into my dll file.now it works.
    Hello,everyone.

  5. #5
    Moderator
    Join Date
    Jul 2005
    Location
    Delhi
    Posts
    15,575
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    7 Thread(s)
    Total Downloaded
    0

    Re: problem about result of a dll

    You had to add the reference because of not using the objects

    Dim cnn As ADODB.Connection
    Dim rst As ADODB.Recordset

    You should be using

    dim cnn,rst

    Code like above in case you want to avoid adding the reference...

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Search Engine Optimisation provided by DragonByte SEO v2.0.36 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 12.50%
vBulletin Optimisation provided by vB Optimise v2.6.4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.2.8 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominate (Lite) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 06:12 PM.

Copyright BetaSoft Inc.