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!

Want to populate a datagrid with a select stmt.

Status
Not open for further replies.

programmerbrian

Programmer
Sep 27, 2002
15
0
0
CA
Hello, I'm looking for a way to display some information from a select stmt, 3 coloumns using a recordset.
I tried to do this with a data grid:

dgdOne.DataSource = adoRecord.open"select col1, 2, 3 from table", DB,static,pessimistic

It doesnt work.

I know that you need to connect to the DB with a data control and then set the datagrids datasource to point to it, but I dont want to do this.

i guess I'm looking for a built in vb6 control that will display my query results in columns, and look nice too. ie no lstboxes with dashes separating the coloums.
Any suggestions?
 
Maybe try using a MSFlexGrid? It's not bound to a data control and should give you the grid that you're wanting.

You'll need to populate the grid yourself, but that's no big task. --
Jonathan
 
You can only set the grid's data source to a recordset (and do not need a data control) at run time.
You can do this for either a DataGrid or a MSHFlex HierarchicalGrid:

Set DataGrid1.DataSource = rsADO
DataGrid1.Refresh

Set MSHFlexGrid1.DataSource = rsADO
MSHFlexGrid1.Refresh

Both grids will then fill up with data.

Please note that you need the OLE DB version of the grids, which you can add under PROJECT|COMPONENTS (it says in the component select window if it is an OLE DB component at the end of the component's name).

(The basic VB6 DBGrid and the basic Flex grids can only be bound to a DAO data control, and that at design time.
So, you do not want these, and do not mistake them for the OLE DB grids.)
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

By the way, I forgot to point out that you need to Set the objects to the datasource, as I missed this in your statements, and, the Cursor location must be adUseClient:

adoRecord.CursorLocation = adUseClient
adoRecord.Open .....

Set DataGrid1.DataSource = adoRecord [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top