PDA

Click to See Complete Forum and Search --> : DBGrid problems


k_ride
Jul 3rd, 2000, 05:55 AM
Hi!

I'm having problems displaying my database.

First I set up my DB with

Set objSource = New clsEyeDB

Then, when I try to set the datasource for my DBGrid with

Set dbData.DataSource = objSource

I end up with an error:
"Run-time error 403:
Class does not support automation or does
not support expected interface"

Also, how do I select which items to display from the
recordset at runtime depending on the users actions, say
"Show all events of type 2 and 4"?

Clunietp
Jul 3rd, 2000, 11:01 AM
1st Question: Are you using ADO recordsets? the DBGrid only supports DAO recordsets

2nd Question: Use a filter on your recordset or requery the database for the specified criteria

k_ride
Jul 4th, 2000, 01:54 AM
Ah, well in that case, how do I fill up a flexgrid with database data. I can get the flexgrid to display the field names with

Set objSource = New MyDBClass

Set FlexGrid.DataSource = objSource

(And MyDBClass is pretty straightforward and works ok) But I can't seem to find a way to fill the grid. All the bound textfields on my form fill up nicely, apparently the Datasource property doesn't work as easily (at least not for me).

Thanks for the feedback,

K

Clunietp
Jul 4th, 2000, 12:46 PM
is objSource an ADO RS or something? what are your custom objects?

k_ride
Jul 5th, 2000, 01:39 AM
OK, here we go..

objSource is an ADODB Recordset.

--- snippet ---

'Class clsEyeDB

Option Explicit
Private rs As ADODB.Recordset

Private Sub Class_GetDataMember(DataMember As String, data As Object)
'Assign the Recordset to the Data Object
Set data = rs
End Sub

Private Sub Class_Initialize()

'Create an instance of the recordset
Set rs = New ADODB.Recordset

'Set the properties of the recordset
With rs
'fields
.Fields.Append "EventID", adInteger

' and so forth..

'other stuff
.CursorType = adOpenStatic
.LockType = adLockOptimistic
.Open
End With

End Sub

--- snippety snip ---

In my program I fill this RS up with data read from an
ASCII file, and this seems to be working fine.

Now I'm (desperately) trying to display the
(filtered/unfiltered) contents of the recordset in a
tabular form, preferrably a flexgrid.

---8<----

Private objSource As clsEyeDB

Private Sub Form_Load()

Set fgData.DataSource = objSource 'fgData is a flexGrid

End Sub

---8<----

Now how do I get the flexGrid to fill up/update with my RS?
Do I have to fill it up row by row or is there a way to
automate this and to have the flexGrid update whenever the
RS changes?

And by custom objects you mean what exactly..?

Clunietp
Jul 6th, 2000, 12:04 AM
ah, your objSource is a data provider

sorry for my ignorance, I haven't played with making a data provider as of yet....

this will put your data into a flexgrid -- you'll want to add column headings and stuff, but this will get you started


Dim cn As New Connection
Dim rs As New Recordset
Dim strRS As String
Dim strRows() As String
Dim i As Long


cn.Open "Provider=Microsoft.jet.OLEDB.4.0;Data Source=Nwind.mdb"

'get rs
rs.Open "Select * from Customers", cn, adOpenStatic, adLockReadOnly, adCmdText

'set number of cols
MSFlexGrid1.Cols = rs.Fields.Count

'get formatted string of data -- use the vbTab because
'that is how the msflexgrid likes it as a parameter
strRS = rs.GetString(, , vbTab, "|", "")

'separate by rows into array
strRows = Split(strRS, "|")

'loop thru array
For i = LBound(strRows) To UBound(strRows)
'add row to grid
MSFlexGrid1.AddItem strRows(i)
DoEvents
Next i

'cleanup....