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
ASKER CERTIFIED SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of developer2012
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
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Yes you can't do that with datareader. Given your requirements, I would use a DataGridView instead of combobox and textboxes.
SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of developer2012
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

SOLUTION
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of developer2012
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!
Avatar of ElrondCT
ElrondCT
Flag of United States of America image

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.
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo