PDA

Click to See Complete Forum and Search --> : Populate DBGrid without using a data control is this possible


Apr 22nd, 2000, 08:47 PM
Ive tried to populate a DBGrid control without using a data control object without success heres some things I tried

Set dbgOrderMaster.DataSource = MR_OS.grstCurrentRS
Set dbgOrderMaster.RecordSource = MR_OS.grstCurrentRS

The recordset MR_OS.grstCurrentRS works fine Ive used it to set some text boxes

Dr_Evil
Apr 24th, 2000, 03:25 AM
Yes it is possible to populate your dbGrid with out using a data control. I prefer to use an ADO connection (Coded not the control) toconnect to the database. From there I use SQL to select the desired fields.

'Query by Chemical Name
Sub cmdQueryChemical_Click()

Dim cnnLabTracking As New Connection
Dim rsChemicalName As Recordset
Dim cmd1 As Command
Dim str1 As String
Dim fldLoop As ADODB.Field


Set cmd1 = New ADODB.Command

With cmd1
.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\My Documents\Access Files\Lab Tracking.mdb;"
.CommandText = "SELECT SampleNumber, `Chemical Name`, `Container Number`, `Container Weight`," & _
"`Description`, `Part Number`, `Batch`, `Screener`, `Department`, `Operator`," & _
"`Date` " & _
"FROM SampleLogin " & _
.CommandType = adCmdText
End With


'Run query.
cmd1.Execute
'Clear data grid
vfgSearchResults.Clear

'Open recordset on cmd1
Set rsChemicalName = New ADODB.Recordset
rsChemicalName.Open cmd1

Do Until rsChemicalName.EOF
vfgSearchResults.AddItem str1, 0
str1 = ""
For Each fldLoop In rsChemicalName.Fields
str1 = str1 & fldLoop.Value & Chr(9)
Next fldLoop
vfgSearchResults.Refresh
Debug.Print str1
rsChemicalName.MoveNext
Loop

rsChemicalName.Close

End Sub

This is just a quick example & may not be exact. It's quitting time now. If you need more help just post & I'll reply asap...

pardede
Apr 24th, 2000, 05:44 AM
If you're using VB6 with ADO you can indeed use a recordset object to fill DBGrid without using data control:

Set DBGrid1.DataSource = YourDB.rsYourRecordset

Apr 24th, 2000, 07:05 PM
Thanks guys. I have MDAC 2.0 and am using data grid 5.0 (sp3)
can only certain grid versions do this?