Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


DataCombo binding

Posted on 1999-07-21
Medium Priority
Last Modified: 2013-11-13
I am using the VB6 DataCombo control.  At runtime I want to bind it to a recorset.  The recordset is the result of an ADO connection to SQL 7 stored proc.  The recordset has the correct data in it.  I used the code from the MSDN - "HOWTO: Bind a DataList or DataCombo to a Recordset at Run-Time" and all I get is an empty drop down.  No errors.  I do not want to use the datacontrol.  Help!
Question by:SiscoKid
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

ID: 1526382
The problem with DBCombo is you have to use datacontrols because at runtime it won't accept the datasource property value.
If you know how to create ActiveX controls then you can add properties to it which will accept the datasource property at run time
LVL 12

Accepted Solution

mark2150 earned 50 total points
ID: 1526383
Set the combo's datasource to a Data control. Then assign the data controls recordset to the result of the SQL:

Set Data1.Recordset = db.OpenRecordset("select * from bmginb7_owner.top10 order by listening_interest, rank", dbOpenSnapshot, dbSQLPassThrough)

This example is from an oracle database.



Author Comment

ID: 1526384
I do not want to use the data contol or the data environment because I want a pure code solution.  The MSDN help shows me how to do it but I can't get it to work.  Is this a known bug?  Is there a kb article on this?  Thanks.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 12

Expert Comment

ID: 1526385
"pure code"?

What the hell does *that* mean?

Is the use of the control somehow "impure"? If it gets the job done, then why not use the tools?

Your original Q indicated that you were using the DataCombo, well the Data control is *part* of how to use a combo.

You can open the database, generate a record set and then populate a listbox or simple grid if you want. Basically you generate you record set and then iterate thru the records filling your grid/listbox as you go:

SET RS=db.OpenRecordset("select * from bmginb7_owner.top10 order by listening_interest, rank", dbOpenSnapshot, dbSQLPassThrough)

  LIST1.ADDITEM trim(RS!{field})
  ... you can also populate a grid with something similar to:
  Grid.Rows = Grid.Rows + 1
  Grid.Col = 1
  Grid.Text = trim( RS!Field1 )
  Grid.Col = Grid.Col + 1
  Grid.Text = trim( RS!Field2 )
  ... etc, etc, etc ...

Once you've generated the record set it matters not what control you assign to handle the task. If you do it as shown above, you have to manage. If you use the data control then it manages.



Author Comment

ID: 1526386
And that is exactly what I am doing, Thanks.  The MSDN is sure misleading on this.  I just don't like populating my form with a bunch of data controls even if invisible at run time.  The pure code phrase is an attempt to convey the desire of NOT having to set properties but have the properties in code so I have more "control".  Does that make any sense ?  The data environment designer is another option that I have uses successfully in the past but again it seems that I loose control if a wayward property gets set during design/debug. Anyway, I think I'm good on this.  You all deserve a better answer than "barely acceptable" so post your answer as an answer and I will gladly grade it.
LVL 12

Expert Comment

ID: 1526387
As a general habit I try to *NOT* set properties at design time for "tough" controls. Like when I use the WinSock control I don't change *ANY* of the properties except at runtime explicitly. This helps me when I copy the code to another project with a fresh copy of the control.

The Data control is *required* even in a "pure code" situation. I've found that if you don't have one, the compiler won't recognize the stinking database commands! If you just start off coding (on a completely blank form) and write something like:


The !@#$%^ compiler will choke with a "Undefined User Type" error!

Placing an *invisible* Data control (with just the default properties) on the form eliminates the error. @#$%^ M$!

Anyway, I see your point, but there really is no clean work around.

Thanx for the offer on pts, but there is no way to re-answer the Q. Don't bother spending more points. I've got plenty! Instead, visit my web page and sign the guestbook. I've got a *lot* of good code online. Check it out!



Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question