1,105,384 Community Members

How to filter a value into a textbox from combox

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

I want to get the relevant name of the product Id into a text box when I select the product id from the combobox

 myConnection = New SqlConnection(connectionstring)
        myConnection.Open()

        myCommand = New SqlCommand(" Select  Name FROM [Product_Name_List] Where P_Id='" & ComboBox2.Text & "'", myConnection)
        Dim dr As SqlDataReader = myCommand.ExecuteReader
        While dr.Read()

            TextBox8.Text = Val(dr(0)).ToString

        End While
        dr.Close()
        myConnection.Close()
Member Avatar
Pgmer
Practically a Posting Shark
881 posts since Apr 2008
Reputation Points: 50 [?]
Q&As Helped to Solve: 158 [?]
Skill Endorsements: 3 [?]
Featured
 
0
 

What is the problem with above code?

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

I want to know to what event in the combobox I have to include this coding.......................

Member Avatar
Reverend Jim
Noli mentula
5,402 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 646 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

You can use SelectedIndexChanged

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

when I used that event I get the default value as 0

Member Avatar
Reverend Jim
Noli mentula
5,402 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 646 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

The default value for what? When you run the following code

Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

    myConnection = New SqlConnection(connectionstring)
    myConnection.Open()

    myCommand = New SqlCommand(" Select  Name FROM [Product_Name_List] Where P_Id='" & ComboBox2.Text & "'", myConnection)
    Dim dr As SqlDataReader = myCommand.ExecuteReader

    ComboBox2.Items.Clear

    While dr.Read()
        Debug.WriteLine(dr(0))
        TextBox8.Text = Val(dr(0)).ToString
    End While

    dr.Close()
    myConnection.Close()

End Sub

what is the output in the debug window?

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

There was no errors
but didn't work as i want..................
when select a item from combox the relevant name of that item didn't display in the textbox.................

Member Avatar
Reverend Jim
Noli mentula
5,402 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 646 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

Run the following code and post the output from the debug window

Private Sub ComboBox2_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

myConnection = New SqlConnection(connectionstring)
myConnection.Open()

myCommand = New SqlCommand(" Select  Name FROM [Product_Name_List] Where P_Id='" & ComboBox2.Text & "'", myConnection)

Debug.WriteLine(myCommand.CommandText)

Dim dr As SqlDataReader = myCommand.ExecuteReader

ComboBox2.Items.Clear

While dr.Read()
    Debug.WriteLine(dr(0))
    TextBox8.Text = Val(dr(0)).ToString
End While

dr.Close()
myConnection.Close()

End Sub

Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

the textbox which the name should be appear become zero and combox become empty
but there is no errors

Member Avatar
Reverend Jim
Noli mentula
5,402 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 646 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

How many times are you planning to ignore my request for you to post the output (in the debug window) from your code?

Question Answered as of 1 Year Ago by Reverend Jim and Pgmer
Member Avatar
Dili1234
Junior Poster
169 posts since Aug 2012
Reputation Points: -2 [?]
Q&As Helped to Solve: 7 [?]
Skill Endorsements: 3 [?]
 
0
 

I didn't ignore your request
I didn't get neither error or output then I changed code like this

  TextBox8.Text = Val(dr(0)).ToString

to

  TextBox8.Text = (dr(0)).ToStrin)

then it started work
Thank you very much to you Sorry If I troubled you........

Member Avatar
Reverend Jim
Noli mentula
5,402 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 646 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

No trouble. Glad you got it working.

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article