How do I fill a DbGrid with a rs?
Printable View
How do I fill a DbGrid with a rs?
are you connecting to your database with a datacontrol or ADO?
ado
here's one method:
there's other methods of course, i had this one open to cut and paste in so it's what i posted :)Code:Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Private Sub Form_Load()
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\path\todb.mdb;Jet OLEDB:Database Password=;User ID=;"
With cmd 'set connection and get records
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "Select * from tablename"
.Execute
End With
With rs
.CursorLocation = adUseClient
.LockType = adLockOptimistic
.Open cmd
End With
Set DataGrid1.DataSource = rs
End Sub
make sure you set a reference to Microsoft Activex Data objects 2.5 library
i took the uid and password out obviously
thank you it works and if ever forget to say thanks it's because I get so wrapped up in what I do I forget.
Thanks
thanks isn't necessary, it is nice occasionally though :D