Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Type MIsmatch in ADO Datagrid

Status
Not open for further replies.

C0PP3R

Programmer
Jun 27, 2002
64
0
0
CA
I am using the Datagrid control called Datagrid (MSDATGRD.OCX) adn I am trying to set it' sdata source to an ADODB recordset and I am getting the Type Mismatch error, any ideas? I know my recordset is returning data (debug.print)

All i removed from my code was the actual SQL statement and the conn string value, everyting els eis identical, any help???

I have checked the below posting, but my prob doe snot seem to be that


Thanks

Copper

Dim dbconn As ADODB.Connection
Set dbconn = New ADODB.Connection

Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseClient

Dim strSQL As String
strSQL = "SQL Select statement..."

Dim strsqlconn As String
strsqlconn = "Connection string"

dbconn.ConnectionString = strsqlconn

'dbconn.CursorLocation = adUseClient

dbconn.Open

Set rst = dbconn.Execute(strSQL)

'rst.Open , , adOpenStatic, adLockBatchOptimistic

If rst.EOF And rst.BOF Then
MsgBox "Error, Part numbers not found, Please try again or see system administrator", vbCritical
Else
'populate the datagrid with the part numbers
With dgListPartNumbers

Set .DataSource = rst
.Refresh
.Caption = "Item Lookup"
.Columns(0).Width = 1000
.Columns(1).Width = 650
.Columns(2).Width = 650

End With


End If
 
Here's one example of how to set up a Datagrid.

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.CursorLocation = adUseClient
cn.Open ConnectionString
Set rs.ActiveConnection = cn
rs.Open "SELECT * FROM tblcustomer", cn
Set DataGrid1.DataSource = rs

Try changing the following line
'Set rst = dbconn.Execute(strSQL)

To this...
Set rst.ActiveConnection = dbconn
rst.open strSQL

Hope this helps! Good Luck
 
Thanks, I got it working, well at least past the type mismatch error, no data is coming up now, but i think i saw this message somewhere in this forum, so I'm gonna have a a look,

I needed to add some references and i got it to work, not sure which it was, but i will post once i know for sure.

Thanks!
 
Does anyone know how to display the selected row and or column data from the currently selected row on an ADO datagrid?
 
Hi,
This post shows a couple different ways Thread222-821754 I was doing the same thing a while back.
Good Luck
 
Awesome, I got it goin, took i a litle since I'm new to usng a datagrid, but they give a nie enough way to display data, jsut gotta learn the logic that goe swith it, jsut a quick opinion question, do most people put the deallocation (ie: rst = nothing, dbconn.close etc...) into the On_Paint event?

Thanks all for feedback
 
Ummm....
I think alot of serious programmers(not all for sure) use class modules(which can easily be converted into COM components or AKA ActiveX components) to create connection objects. And inside the class_terminate event make sure all clean up is done. If your not using this technique then I would do my clean up immediately after the connection is no longer needed which could be in the form_unload event or even inside the procedure that created it. There's good conversation in a recent thread(past 2-3 days) about closing connection or keeping it open throughout the life of the application.

Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top