devxlogo

Load a Grid From a SQL Statement

Load a Grid From a SQL Statement

Here is useful code for a generic routine to load a grid from anSQL statement. The example shown is for RDO and Sheridan’s grid,but works with minor modification for any grid and result set type.Also, you can load combo boxes in a similar fashion:

 Public Sub LoadGridFromSQL(TargetGrid As SSDBGrid, rdoConn As rdoConnection, Sql As String, Optional ClearGrid As Boolean = True)    Dim J As Integer    Dim rsResult As rdoResultset    Dim sAddItem As String        If ClearGrid Then        TargetGrid.RemoveAll    End If    TargetGrid.Redraw = False        Set rsResult = rdoConn.OpenResultset(Sql, rdOpenForwardOnly, rdConcurReadOnly, rdExecDirect)    With rsResult        Do Until .EOF                        'Build add item string            sAddItem = vbNullString            For J = 1 To .rdoColumns.Count                If IsNull(.rdoColumns.Item(J - 1)) Then                    sAddItem = sAddItem & vbNullString & vbTab                Else                    sAddItem = sAddItem & .rdoColumns.Item(J - 1) & vbTab                End If            Next J                        'Remove extra tab from end            TargetGrid.AddItem Left$(sAddItem, Len(sAddItem) - 1)            .MoveNext                Loop        .Close    End With 'rsResult        TargetGrid.Redraw = True    Set rsResult = Nothing    End Sub
See also  The Art of AI-Generated Meeting Minutes
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist