Results 1 to 4 of 4

Thread: Functions Returning Recordsets

  1. #1

    Thread Starter
    Hyperactive Member razzaj's Avatar
    Join Date
    Oct 1999
    Location
    jounieh
    Posts
    261
    I am writing a DLL that is to be used from ASP.
    some functions in my classes have to return a REcordset.
    of type ADODB.REcordset.

    here is how I wrote the functions :



    Code:
    public function GetUsers (Catid as Integer) as ADODB.Recordset
    
    dim Rec as ADODB.REcordset
      
    [ ... perform any selection from database ... ]
    
      'Store Results in REC
    
       ' Return Results
       Set  GetUsers = Rec
    
    
    End function


    In ASP I used the following code to call this function:



    Code:
    <%
     Dim COmObj
     DIm Rec 
    
     Set Rec = Server.CreateObject("ADODB.REcordset")
     Set ComObj = Server.CreateObject("MyObj.MyClass")
    
      Rec = COmObj.GetUSers(10)
    %>
    bu I am getting an Error in My Dll "Object or Block Variable not Set"

    now it is clear some thing is wrong. But what.
    Please any help is greatly appreciated
    - regards -
    - razzaj -

  2. #2
    bubba
    Guest
    I prefer to handle all my business in the dll and then just return HTML to the calling asp, but I have worked on a couple of projects where we had to handle it differently and had to pass the recordset back to asp.

    Here is a good way to handle recordsets returned from DLLs to ASP:

    In your asp:
    Look for an error string as the return, but pass the empty recordset as a parameter:

    Set Rec = Server.CreateObject("ADODB.REcordset")

    error = COmObj.GetUSers(10, Rec)

    That way you can handle error messages returned from the dll....

    In your DLL:
    Declare your function as a string, and pass the record byRef as a variant:

    Code:
    public function GetUsers (Catid as Integer, byRef vntRecord as variant) as string
    
    dim Rec as ADODB.REcordset
      
    [ ... perform any selection from database ... ]
    
      'Store Results in REC
    
    
    
    'Add fields to vntRecord from Rec    
    'vntRecord won't have the intellisense enabled for the properties, but this does work
            
    For intField = 0 To Rec.Fields.Count - 1
       vntRecord.Fields.Append Rec.Fields(intField).Name, Rec.Fields(intField).Type, Rec.Fields _
    (intField).DefinedSize, Rec.Fields(intField).Attributes
    Next
    
    vntRecord.Open , , adOpenDynamic
            
    'get the data from the recordset into the result recordset
    
    liNoOfFields = Rec.Fields.Count
    iNoOfRecords = Rec.RecordCount
    
    
    If Rec.RecordCount > 0 Then
             Rec.MoveFirst
              For liCurrentRecord = 0 To liNoOfRecords - 1 Step 1
                        vntRecord.AddNew
                        For liCurrentField = 0 To liNoOfFields - 1 Step 1
                            vntRecord(liCurrentField).Value = Rec(liCurrentField).Value
                        Next liCurrentField
                        vntRecord.Update
                        Rec.MoveNext
                    Next liCurrentRecord
                
       ' Return Results
       
    Set  GetUsers = "OK"
    
    Exit Function
    
    Errhandler:
    GetUsers = "Error"
    End function
    Now Rec in your asp contains the recordset, and you are able to check for error returned by the DLL.

  3. #3
    Junior Member
    Join Date
    Apr 2001
    Location
    Manassas, Va.
    Posts
    18

    Declare Recordset as NEW

    In your DLL declare your recordset as New. This will eliminate your error.

    Code:
    Dim Rec as New ADODB.Recordset

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Also:

    Code:
    <%
     Dim COmObj
     DIm Rec 
    
     Set ComObj = Server.CreateObject("MyObj.MyClass")
    
     Set Rec = ComObj.GetUSers(10)
    %>
    No need to set the Rec object to a recordset first. And you DO need to use the Set keyword to set the Rec object reference to the returned recordset.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width