Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Getting Datagrid to display SQL results with ADODB connection

Getting Datagrid to display SQL results with ADODB connection

Getting Datagrid to display SQL results with ADODB connection


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:


  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!

RE: Getting Datagrid to display SQL results with ADODB connection

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

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: How to get the best answers before posting.


RE: Getting Datagrid to display SQL results with ADODB connection

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,


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close