|
-
Aug 15th, 2000, 10:13 AM
#1
Thread Starter
Member
I want to display data in a DBGrid. I create a recordset at runtime. Is there a way i can use the values from the recordset and display them in the DBGrid?
Is there any other way that might be better to do this?
Thanks in advance
-
Aug 16th, 2000, 03:29 AM
#2
Hyperactive Member
Is this a DBGrid as in VB5 or a DataGrid as in VB6 ?
That's Mr Mullet to you, you mulletless wonder.
-
Aug 16th, 2000, 09:10 AM
#3
Thread Starter
Member
-
Aug 16th, 2000, 10:09 AM
#4
Fanatic Member
set the Datasource property of the datagrid to the recordset you have created
Code:
Set DataGrid1.DataSource = Adodc1
Then with the datagrid on the form right click and choose 'properties'
On the columns tab select the column and designate a caption then specify the database column you are binding.
Take a look at the other settings while you are there like update, and addnew settings.
The headers can also be done in code
Code:
DataGrid1.Columns.Add(0).Caption = "Au_ID"
Do this for each column you want.
-
Aug 16th, 2000, 10:19 AM
#5
Fanatic Member
Don't forget to use the 'Retrieve Fields' option from the pop up menu when you have right clicked on the control after assigning the recordset to the datagrid
-
Aug 16th, 2000, 11:04 AM
#6
Thread Starter
Member
I recieved an error that said:
"class does not support automation or does not support expected interface"
This is what i did. I wrote code on the onload,
set dbgrid1.datasource = rsfeatures
then i went into properties on the dbgrid, and on the columns tab, entered the database field which was called feature_number into the datafield combobox.
My recordset is being created at runtime, so i don't know how it would recognize it being bound to the DBGrid.
Am i forgetting to do something, or is there a different way to do this?
-
Aug 17th, 2000, 03:30 AM
#7
Fanatic Member
Are you using ADO or DAO?
The Data Environment, Data Control or strictly code to set up the recordset?
Is the database Access or SQL server?
-
Aug 17th, 2000, 05:18 AM
#8
Fanatic Member
I got the error you described when I used tried using an ADO recordset with a DBGrid instead of a DataGrid. A DBGrid is DAO not ADO compatible a DataGrid is. When I used a DataGrid with an ADO recordset as in the code below there was no problem, I didn't even have to set any of the properties of the DataGrid at all just place a DataGrid on a form, place the following code on the form and 'hey presto', Bob's your Auntie.
Code:
Option Explicit
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Private Sub Form_Load()
Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open '<COnnectionString>
rs.Open "SELECT * from staff", cnn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
End Sub
You may want to play around with the rs.open cursor and locking parameters
-
Aug 17th, 2000, 01:50 PM
#9
Thread Starter
Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|