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
Solved

Issue with finding sql table ID in VB.Net combobox

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

Suggested Solutions

Title # Comments Views Activity
OSQL to execute sql command 26 24
SSRS Deployment problem 5 64
changing page verifacation 1 26
question about results where i dont have a match 3 20
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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.

856 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