VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset.

by Karthik Nagaraj (1 Submission)
Category: OLE/COM/DCOM/Active-X
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 4th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset. Replace "grdResults" in the code with your

Rate Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset.



    Dim liColNum As Integer
    Dim liNumOfCols As Integer
    Dim liRowNum As Integer
    Dim liNumOfRows As Integer
    Dim lsRowVal As String
    Dim lsBoolVal As String

    ' ---- Initialize column number
    liColNum = 1
    ' ---- Initialize grid
    grdResults.Clear
    grdResults.Col = 0
    grdResults.Row = 0
    
    ' ---- Get # of Columns
    grdResults.Cols = lsResultSet.Fields.Count + 1
    
    ' ---- Move pointer to first record
    If Not lsResultSet.BOF Then
        lsResultSet.MoveFirst
    End If
    
    ' ---- Get # of Rows
    Do Until lsResultSet.EOF
        liNumOfRows = liNumOfRows + 1
        lsResultSet.MoveNext
    Loop
    
    ' ---- Fill the headers first
    For Each gsFldSet In lsResultSet.Fields
        grdResults.Col = liColNum
        liColNum = liColNum + 1
        grdResults.Text = gsFldSet.Name
    Next
        
    ' ---- Move pointer to first record
    If Not lsResultSet.BOF Then
        lsResultSet.MoveFirst
    End If
    liRowNum = 0
            
    ' ---- Total # of rows one more than actual #
    grdResults.Rows = liNumOfRows + 1
    
    ' ---- Populate grid with table data
    Do While Not lsResultSet.EOF
        liColNum = 0
        liRowNum = liRowNum + 1
        For Each gsFldSet In lsResultSet.Fields
            liColNum = liColNum + 1
            grdResults.Col = liColNum
            grdResults.Row = liRowNum
            If gsFldSet.Value = "" Then
                grdResults.Text = "NULL"
            ElseIf gsFldSet.Type = adBoolean Then
                lsBoolVal = gsFldSet.Value
                If lsBoolVal = "True" Then
                    grdResults.Text = "1"
                Else
                    grdResults.Text = "0"
                End If
            Else
                grdResults.Text = gsFldSet.Value
            End If
        
        Next
        lsResultSet.MoveNext
    Loop
End Function


Download this snippet    Add to My Saved Code

Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset. Comments

No comments have been posted about Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset.. Why not be the first to post a comment about Populates the MSFlexGrid control with data from ADODB recordset. Input Parameter : ADODB recordset..

Post your comment

Subject:
Message:
0/1000 characters