Avatar of developer2012
developer2012
 asked on

How to display corresponding values of combo box in text box?

Hi there,

I have a vb.net application in which I have a combo box and text boxes.

Combo Box display all employee ID When I select any ID the below text boxes should display the attributes associated with Id. For example, If I select my id 1001 in combo  box then all the text boxes should display my name, last name,  city, phone number  

Any ideas how to achieve it?

Thanks!
Visual Basic.NET

Avatar of undefined
Last Comment
ElrondCT

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ElrondCT

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Nasir Razzaq

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
developer2012

ASKER
@ Code Cruiser. Thanks I got you. But I  think I can not make changes to data it if I am reading through data reader. When the values  appear in the text boxes. I am supposed to edit, delete, or add new record to it. Thanks
Nasir Razzaq

Yes you can't do that with datareader. Given your requirements, I would use a DataGridView instead of combobox and textboxes.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
developer2012

ASKER
This is how I am loading data in to combo box.

   Private Sub BuildDotCB()
        Dim dsDot As New DataSet
        Try
            DotCB.Items.Clear()
            Dim QueryString As String = "Select Distinct ID FROM tblSystemInformationEmployee "
            Dim drow As DataRow
            drow = Nothing
            dsId = New DataSet
            dsId= GetResultDataset(QueryString, ConnectionString)
            If IsValidDataset(dsDot) Then
                For Each drow In dsId.Tables(0).Rows
                    DotCB.Items.Add(drow(0).ToString())
                Next
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
developer2012

ASKER
I wrote this data view function to manipulate the values as below.
  Private Sub ViewMode(ByVal GUID As String)
        Try

            Dim viewDs As New DataSet()
            Dim Query As String
            Query = "Select * from tblSystemEmployee Where UID = '" & GUID.Trim & "'"
            viewDs = GetResultDataset(Query, True)

            Dim dv As DataView = New DataView(viewDs.Tables(0))
            Dim Notify As String = String.Empty
            If dv.Count > 0 Then

                If Not IsDBNull(dv(0)("UID")) Then
                    txtHWGUID.Text = dv(0)("UID")
                Else
                    txtHWGUID.Text = String.Empty
                End If

              

                If Not IsDBNull(dv(0)("StreetName")) Then
                    txtHWStName.Text = dv(0)("StreetName")
                Else
                    txtHWStName.Text = String.Empty
                End If
            End If
        Catch ex As Exception
            MsgBox("No Values Found")
        End Try
    End Sub

Open in new window


And called the above function on the selectionChangedEvent like this :

Private Sub IDCB_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs) Handles IDCB.SelectionChanged
        StreetCB.IsEnabled = False

        ViewMode(IDCB.SelectedItem.ToString)

Open in new window


and When I select any value it show me "No Value found".

Am I missing any thing?

Please help me through this issue.
\
P.S. It is a WPf application.

Thanks!
ElrondCT

Since you're getting "No values found", which is the message that is generated by getting an exception, it suggests that either you're getting an error from the query itself, or you're getting a record, but there's a problem in referencing it. Use the debugger to go through line by line. Which line is giving you the error? Offhand, my first thought is that you've specified one of the field names incorrectly (UID or StreetName), but you'd need to find which line is the problem to know for sure.