rbertke
asked on
True DBGrid wont bind to recordset
I am trying to use a True DBGrid control and I have reduced my code to a very small snippet which I believe should work. Whats interesting is that similar code (in fact very similar), works just fine on another form.
Details below...Can anyone help?
On form the TDBGrid is named grdFields and I have a
private Connection object named 'rsCertConnection' and
a private Recordset object named 'rsShow'
The forms OnLoad event is as follows:
NOTE: I have a message box in the code which returns '51'
the number of records in that table. So I know its
not the connection string or the SQL statement.
------------------------
Dim strSQL As String
Set CertConnection = New ADODB.Connection
Set rsShow = New ADODB.Recordset
strSQL = "Provider=Microsoft.Jet.OL EDB.3.51; _
PersistSecurity Info=False;Data Source=" _
& strAppDataPath
CertConnection.Open strSQL
strSQL = "SELECT [State], [StateAbriv] AS _
[State Abriviation] FROM tblzLuState"
rsShow.Open strSQL, CertConnection, adOpenKeyset,_
, adCmdText
MsgBox rsShow.RecordCount 'Returns '51'
Set grdFields.DataSource = rsShow
Details below...Can anyone help?
On form the TDBGrid is named grdFields and I have a
private Connection object named 'rsCertConnection' and
a private Recordset object named 'rsShow'
The forms OnLoad event is as follows:
NOTE: I have a message box in the code which returns '51'
the number of records in that table. So I know its
not the connection string or the SQL statement.
------------------------
Dim strSQL As String
Set CertConnection = New ADODB.Connection
Set rsShow = New ADODB.Recordset
strSQL = "Provider=Microsoft.Jet.OL
PersistSecurity Info=False;Data Source=" _
& strAppDataPath
CertConnection.Open strSQL
strSQL = "SELECT [State], [StateAbriv] AS _
[State Abriviation] FROM tblzLuState"
rsShow.Open strSQL, CertConnection, adOpenKeyset,_
, adCmdText
MsgBox rsShow.RecordCount 'Returns '51'
Set grdFields.DataSource = rsShow
ASKER
I have tried that (just tried again), that doesnt do it.
The code is pretty simple, its got to be something Im
overlooking.
The code is pretty simple, its got to be something Im
overlooking.
I am not that familar with the TDBG but does the grdFields have a RecordSource property. If it does try
grdFields.RecordSource = rsShow
then the refresh
grdFields.RecordSource = rsShow
then the refresh
Look at #8 at this link for an example
http://www.vbxtras.com/vbhowto/VBHowTo69.txt
http://www.vbxtras.com/vbhowto/VBHowTo69.txt
Have you tried VB TA? (and their response was ...?)
https://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/
https://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK, I have figured out issue. As dumb as it seems, I was
using the wrong control. True DBGrid comes with an OLEDB
control and a non-OLEDB control. I had inadvertantly
used the wrong control. Obviously, the non-OLEDB control
will not accept an ADO recordset as a bindable object.
Points go to rajesh_chd because that method does work
in either control...And it was messing with this code
that made me realize the issue.
Thanks All!
using the wrong control. True DBGrid comes with an OLEDB
control and a non-OLEDB control. I had inadvertantly
used the wrong control. Obviously, the non-OLEDB control
will not accept an ADO recordset as a bindable object.
Points go to rajesh_chd because that method does work
in either control...And it was messing with this code
that made me realize the issue.
Thanks All!
Set grdFields.DataSource = rsShow
try using
grdFields.Refresh