CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Recordset in VB

  1. #1
    Join Date
    Jul 2000
    Posts
    67

    Recordset in VB

    Good Morning!

    Do somebody know how to get data out of a recordset and into variables? As you can see in the code below, I do a loop on the recordset, and make a print. My problem is that I want to get the each value/field in the recordset into variables first, so I can print it in the order i want afterwords. Now do i get everything into sData variable, and then i am not able to change the order of fields when i do a print...

    Do you have a suggestion? Thankful for all answers!


    Dim rsAddresses As ADODB.Recordset
    Dim rsNames As ADODB.Recordset
    Dim paf As PafSearchR
    Dim fld As ADODB.Field
    Dim sData As String



    Set paf = CreateObject ("nbPAFSearchR.PafSearchR")

    Set rsAddresses = paf.DoPafSearch(FullPostCode, BuildingNo, "", "", "", "", "", 80, True, 100, True)



    Open PrintFile For Append As #1 ' Open outputfile for append.

    Set rsNames = paf.GetNames
    rsAddresses.RecordCount & ")")
    sData = ""
    For Each fld In rsAddresses.Fields
    sData = sData & fld.Name & ", "
    Next
    Do Until rsAddresses.EOF
    sData = ""
    For Each fld In rsAddresses.Fields
    sData = sData & fld.Value & ", "
    Next
    ' Call Trace(sData)
    rsAddresses.MoveNext
    Print #1, sData; 'prints address
    Loop










  2. #2
    tdeltax Guest

    Re: Recordset in VB

    hi
    u can use a multidimension text array to get all the data from the recordset.
    now that u have the text array u can access the data in the order u want by specifying the indexes of the text array.

    i hope this solves ur problem



  3. #3
    Join Date
    Oct 2001
    Posts
    55

    Re: Recordset in VB

    hi
    u can use a multidimension text array to get all the data from the recordset.
    now that u have the text array u can access the data in the order u want by specifying the indexes of the text array.

    i hope this solves ur problem



  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Recordset in VB

    Save data from rs to 2d array

    Function RecordsetToVarArray(oRst As ADODB.Recordset) As Variant()

    Dim avarStuff() As Variant ' Hold the returned records
    Dim fldThis As ADODB.Field ' Iterator for the Fields collection
    Dim iIndex As Integer ' Loop index

    ' Resize the array to hold the column names
    ReDim avarStuff(1 To oRst.Fields.Count, 0 To 0) As Variant

    ' Extract all the column names from the Fields collection
    iIndex = 1
    For Each fldThis In oRst.Fields
    avarStuff(iIndex, 0) = fldThis.Name
    iIndex = iIndex + 1
    Next fldThis

    ' Move to the first record in the recordset
    oRst.MoveFirst

    ' Loop through the records, and build the 2-D array
    Do While Not oRst.EOF
    ReDim Preserve avarStuff(LBound(avarStuff, 1) To UBound(avarStuff, 1), _
    LBound(avarStuff, 2) To (UBound(avarStuff, 2) + 1)) As Variant

    For iIndex = LBound(avarStuff, 1) To UBound(avarStuff, 1)
    avarStuff(iIndex, UBound(avarStuff, 2)) = _
    oRst.Fields(avarStuff(iIndex, 0)).Value
    Next iIndex

    oRst.MoveNext
    Loop

    ' Return the array
    RecordsetToVarArray = avarStuff()
    End Function

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured