Solved

Issue with finding sql table ID in VB.Net combobox

Posted on 2016-07-18
2
48 Views
Last Modified: 2016-07-18
I have loaded a combobox in VB.Net with the following code:
Dim conn As New SqlConnection(sqlComm)

        Try

            Dim sSQL As String
            sSQL = "SELECT  strSelect from tvwSelect order by strSelect"
            Dim dbadp As New SqlDataAdapter(sSQL, sqlComm)
            Dim dTable As New DataTable
            dbadp.Fill(dTable)
            dbadp.Dispose()

            Me.cboRecord.DisplayMember = "strSelect"
            Me.cboRecord.ValueMember = "numLeadID"
            Me.cboRecord.DataSource = dTable


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        conn.Close()
        conn = Nothing

Now I want to click on an item in the combobox and retrieve the numLeadID number so I can grab that record from the database. I am new to .Net and don't know how to go about this. I tried to see what I was selecting with this code:MsgBox(cboRecord.SelectedValue) but I got an error message. I will supply more info or clarify if necessary.
0
Comment
Question by:smm6809
[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 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 41717196
>> I got an error message

It would really help to know which error?

One thing I see is that your query to fill the combo does not retrieve the numLeadID field. It probably needs to read:
sSQL = "SELECT numLeadID , strSelect from tvwSelect order by strSelect"

Open in new window

0
 

Author Comment

by:smm6809
ID: 41717225
That solved it. Thank you so much!
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

739 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