Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Jul 16, 1999

Load a Grid from a SQL Statement

Use this code for a generic routine to load a grid from a SQL statement. The example is for Remote Data Objects (RDO) and Sheridan Software Systems' grid, but it works with minor modification for any grid and resultset 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
Joe Karbowski
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date