Solved

VB Application combobox 2 values

Posted on 2010-11-21
4
264 Views
Last Modified: 2012-05-10
Hi,

I am wondering a good way to assign the displayed text and the ID value to a combobox in a VB application.
This is windows application not a web app.

I know you can do this easily in a web app, but I am having trouble in a windows app.

In the code below you can see I am grabbing the ID and the name. I want to display the Name in the combobox, but use the selected ID in the next SQL Statement not the name.

Thanks
Fixitben
Imports System.Data.Odbc
Public Class WOSUB
    Public connectionstring As String
    Private Sub WOSUB_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        connectionstring = "DRIVER={SQL Server};SERVER=xxxx;Trusted_connection=yes;DATABASE=xxxx;"
        Dim queryString As String = "SELECT  WO_TYPE,WO_TYPE_ID FROM WO_TYPE"
        Using connection As New OdbcConnection(connectionstring)
            Dim command As New OdbcCommand(queryString, connection)
            connection.Open()

            Dim reader As OdbcDataReader = command.ExecuteReader()
            'Goes through Multi-Dem array and adds each row to the combobox vendor
            While reader.Read()
                WOTYPEComboBox1.Items.Add(RTrim(reader(0).ToString))
            End While

            ' Call Close when done reading.
            reader.Close()

        End Using

Open in new window

0
Comment
Question by:fixitben
[X]
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
  • 2
4 Comments
 
LVL 19

Expert Comment

by:weellio
ID: 34185350
i believe you can bind it to a datasource and use the displaymember/valumember attribute.

where you see the displaymember and can pull the value member from a simple for/next loop
0
 
LVL 7

Author Comment

by:fixitben
ID: 34185355
Yes I know that. But as you can see I am not binding the datasource via the gui.

Is there a way to do this using code?

Thanks
Fixitben
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 34185432
0
 
LVL 7

Author Closing Comment

by:fixitben
ID: 34185479
This worked great!!!!!!!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Starting up a Project

717 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