Solved

Issue with finding sql table ID in VB.Net combobox

Posted on 2016-07-18
2
28 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
2 Comments
 
LVL 69

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now