473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Trying to populate a combobox

PGM
I am trying to populate a combo box using a simple SQL query to a database
but all I get in the combo box is "System._ComObject" . Any suggestions are
greatly appreciated

On Error Resume Next

Dim strSQL As String

Dim strConn As String

Dim i As Integer

strSQL = "SELECT F2 FROM dbo.Masterserver WHERE F2 like 't%'"

strConn = "Provider=SQLOLEDB.1;Password=vbuser;Persist Security
Info=True;User ID=VBuser;Initial Catalog=Masterserver;Data
Source=patmtest\sqlexpress"

MyConnObj = New ADODB.Connection

MyConnObj.Open(strConn)

cmdselect = New ADODB.Command

cmdselect.ActiveConnection = MyConnObj

cmdselect.CommandText = strSQL

myRecSet = New ADODB.Recordset

myRecSet.Open(strSQL, MyConnObj, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic, ADODB.CommandTypeEnum.adCmdText)

MsgBox("Total Number of records = " & myRecSet.RecordCount) 'Test SQL query

ComboBox1.Refresh()

myRecSet.MoveFirst()

For i = 1 To myRecSet.RecordCount

ComboBox1.Items.Add(myRecSet.Fields("F2"))

Next i

myRecSet.Close()

MyConnObj.Close()

myRecSet = Nothing

MyConnObj = Nothing

Jun 27 '08 #1
3 1043
"PGM" <pm*******@chw.orgschrieb
I am trying to populate a combo box using a simple SQL query to a
database but all I get in the combo box is "System._ComObject" . Any
suggestions are greatly appreciated

Is there a reason why you use COM Interop (ADO) instead of ADO.Net?

ComboBox1.Items.Add(myRecSet.Fields("F2"))
You add a field. It's ToString method returns the data type, which is
"System._ComObject". The combobox always displays the string returned by
the object's ToString method.

Use
myRecSet.Fields("F2").Value.ToString
instead.
Armin

Jun 27 '08 #2
"Armin Zingler" <az*******@freenet.deschrieb
Use
myRecSet.Fields("F2").Value.ToString
instead.
Of course,
myRecSet.Fields("F2").Value
works, too (because of the reason given before).
Armin
Jun 27 '08 #3
PGM
A novice at work

"Armin Zingler" <az*******@freenet.dewrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
"PGM" <pm*******@chw.orgschrieb
>I am trying to populate a combo box using a simple SQL query to a
database but all I get in the combo box is "System._ComObject" . Any
suggestions are greatly appreciated


Is there a reason why you use COM Interop (ADO) instead of ADO.Net?

>ComboBox1.Items.Add(myRecSet.Fields("F2"))

You add a field. It's ToString method returns the data type, which is
"System._ComObject". The combobox always displays the string returned by
the object's ToString method.

Use
myRecSet.Fields("F2").Value.ToString
instead.
Armin

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: godber | last post by:
I need to populate text boxes for instance with employee information using their unique employee works number selected from a combo box. Can anyone help, I am told thru visual basic this can be...
4
by: Mike L | last post by:
I'm open for any suggestions on how to better program this. I want the user to select a license from a combo box, cboPrivilege and then the user will click the add button, then a record will be...
1
by: Henry | last post by:
I hope someone can help me on this. I have two controls on a form. the first is a comboBox the second is a datagrid. Both controls are bound to tables in a common dataset. What I am trying to...
16
by: agrawal.solutions | last post by:
Hello Friends I am asking a very silly question but i dont find any solution fo this.. I am selectiong a recordset and want to populate a combobox where id would be inviseble and the content...
2
by: rperreta | last post by:
I exported a xml file using .writexml from a dataset and now I would like to populate a combo box from that. Can someone supply a link or sample vb.net code that show's how to do this... much...
5
by: Rich | last post by:
Hello, I have a search application to search data in tables in a database (3 sql server tables). I populate 2 comboboxes with with data from each table. One combobox will contain unique...
4
by: polaris431 | last post by:
All the examples I've seen showing how to populate a combobox using the DataSource property and an ArrayList show the ArrayList object containing objects with at least two properties. I want to...
1
by: freekedoutfish | last post by:
Hi. New member here Im sat at work, pounding my head off the desk because this tiny bit of simple code refuses to work. The sub is intended to pull data from the "companyname" column in the...
0
TonFrere
by: TonFrere | last post by:
Hello, I'm building a windows form application in Visual C# using VS 2005. On my form I need to populate a combobox with Invoices# linked to the current reccord's Order# value. This means that: -...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.