Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Issue with finding sql table ID in VB.Net combobox

Posted on 2016-07-18
2
Medium Priority
?
55 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 70

Accepted Solution

by:
Éric Moreau earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

783 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