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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Datagrid to display SQL results with ADODB connection

Status
Not open for further replies.

WalterHeisenberg

Technical User
Mar 28, 2008
159
Hello,

First I'll make no attempt to hide I am an absolute beginner when it comes to VB. I've been given an application and asked to "enhance" it with no prior vb experience.

Thus far I've made the "eye candy" changes needed with various labels and check boxes etc. However, I cannot get the results of a SQL query to display in a datagrid using the DBGrid control. I have been able to display items in a listbox but ultimately I will need to get this datagrid working.

After building my query based on user input, I am using:
Code:
  Set rst = New Adodb.Recordset
    rst.Open sql, cn, adOpenStatic, adLockReadOnly, adCmdText

where sql is the SQL statement and cn is the connection string. Again, I can results to display in a label or listbox but can't get them to show on the datagrid. I tried adding, "set DBGrid.datasource = rst but get "class not support automation or does not support expected interface". Many thanks in advance for help!
 
I'm thinking the DBGrid is designed (and I don't use them so I could be corrected on this) to be used with the bound data controls you can add to your form rather than to work with dynamically created recordsets.

You could replace it with a 'Microsoft Datagrid Control' instead and the syntax you used in your post will populate that grid with records (as long as you specify the cn.CursorLocation = adUseClient).

Hope this helps

HarleyQuinn
---------------------------------
Carter, hand me my thinking grenades!

You can hang outside in the sun all day tossing a ball around, or you can sit at your computer and do something that matters. - Eric Cartman

Get the most out of Tek-Tips, read FAQ222-2244: How to get the best answers before posting.

 
Just an update, the code I had inherited was part of an Enterprise Application and as such I was running into problems with the controls I could use. I am going to rewrite this as a windows app. so I have more information at my fingertips. I'm sure I'll run into problems shortly! :). Thanks,

Ariel
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top