Solved

VB Application combobox 2 values

Posted on 2010-11-21
4
262 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Eclipse with various Java releases 7 48
VB.Net - String Manipulation Scenario 2 29
Need help converting bitmap to image in VB.Net 8 45
Filtering a datagrid view 8 34
In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

749 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