Solved

Issue with finding sql table ID in VB.Net combobox

Posted on 2016-07-18
2
39 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 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

773 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