none
How Do I fill A combobox From A SQL table Based on selected text on a textbox RRS feed

  • Question

  • Hi Good People

    On my Form I have Three Radio Button And when one of the Radio Buttons is checked then a value of the Radio Button Is put into a Textbox. i.e. " 4 SEAT VEHICLE "  " 6 SEAT VEHICLE "  " 8 SEAT VEHICLE "  

    Now is what I am trying to do is get my Combo box to list only a driver Call sign  for a driver driving " 8 SEAT VEHICLE "  Or If A Driver is Driving a   " 6 SEAT VEHICLE " only Drivers Driving  " 6 SEAT VEHICLE " And  Or   " 8 SEAT VEHICLE " Because a      " 8 SEAT VEHICLE " Can Do  " 6 SEAT VEHICLE " job

    or If a Driver is Driving a  " 4 SEAT VEHICLE " I want the Combo box to List  Driver Call sign  for Driver only Driving " 4 SEAT VEHICLE " and or  " 6 SEAT VEHICLE " Because  " 6 SEAT VEHICLE " can do a  " 4 SEAT VEHICLE " job

    Is there a way for the Combo box to List only the what Vehicle the Driver is Driving,   The Call sign is for a Radio Operator  to call the specific Driver to do a job... I have tried Numerous way Looked At Video's etc. The code I have But does not work Might See what My issue is......

     Private Sub GetVehicle(NumberOfSeats As String, DriverCallsign As String)
    
            Dim V1 As String = txtVehicleRequired.Text
            ' SELECT FROM VEHICLE TABLE NUMBER OF SEATS AND DRIVERCALLSIGN
            SQL.ExecQuery("SELECT NumberOfSeats, DriverCallsign From Vehicle")
            If SQL.RecordCount > 0 Then
                'IF 4 SEAT VEHICLE IS SELECTED, THEN GET ALL DRIVERS DRIVING 4 SEAT VEHICLE, THEN GET 4 SEAT VEHICLE DRIVERS ONLY INTO COMBOBOX, 
                If txtVehicleRequired.Text = "4 SEAT VEHICLE" Then
                    For Each V1 In SQL.SQLDT.Rows.Contains("4 SEAT VEHICLE").ToString
                        cbxDriverCallsign.Items.Add(V1("DriverCallsign").ToString)
                    Next
                    'IF 6 SEAT VEHICLE IS SELECTED, THEN GET ALL DRIVERS DRIVING 6 SEAT VEHICLE, THEN GET 6 SEAT VEHICLE DRIVERS ONLY INTO COMBOBOX, 
                ElseIf txtVehicleRequired.Text = "6 SEAT VEHICLE" Then
                    For Each V1 In SQL.SQLDT.Rows.Contains("6 SEAT VEHICLE").ToString
                        cbxDriverCallsign.Items.Add(V1("DriverCallsign").ToString)
                    Next
                    'IF 8 SEAT VEHICLE IS SELECTED, THEN GET ALL DRIVERS DRIVING 8 SEAT VEHICLE, THEN GET 8 SEAT VEHICLE DRIVERS ONLY INTO COMBOBOX, 
                ElseIf txtVehicleRequired.Text = "8 SEAT VEHICLE" Then
                    For Each V1 In SQL.SQLDT.Rows.Contains("8 SEAT VEHICLE").ToString
                        cbxDriverCallsign.Items.Add(V1("DriverCallsign").ToString)
    
                    Next
                End If
            End If
    
    
        End Sub
     

    Kind Regards

    Gary


    Gary Simpson


    Thursday, November 2, 2017 11:54 PM

Answers

  • I am assuming that the NumberOfSeats field is a string which will match your text box.
        
    Private Sub FillCombo()
            Dim strSeats = txtVehicleRequired.Text
            Dim cn As New SqlConnection("Connection String")
            Dim cmd As New SqlCommand With {
                .Connection = cn,
                .CommandType = CommandType.Text,
                .CommandText = "Select NumberOfSeats, DriverCallsign From Vehicle"}
            cn.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader
            Do While dr.Read
                If dr.GetString(0) = strSeats Then
                    ComboBox1.Items.Add(dr.GetString(1))
                End If
            Loop
        End Sub
    forgot cn.Close

    Mary

    • Marked as answer by Gary Simpson Friday, November 3, 2017 4:52 PM
    Friday, November 3, 2017 6:58 AM

All replies

  • Hi Gary,

    According to your description, you said that you have three RadioButton, names are " 4 SEAT VEHICLE "  " 6 SEAT VEHICLE "  " 8 SEAT VEHICLE ". When you check only one RadioButton, the value will put into Textbox, it is very clear. But I am not sure how to fill the ComBoBox when you chose one RadioButton. For example, you check  "4 SEAT VEHICLE"  RadioButton , what data the ComboBox should be bound  to, 6 SEAT VEHICLE " RadioButton and  " 8 SEAT VEHICLE " RadioButton ? Please help us to confirm it.

    Best regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 3, 2017 6:30 AM
    Moderator
  • I am assuming that the NumberOfSeats field is a string which will match your text box.
        
    Private Sub FillCombo()
            Dim strSeats = txtVehicleRequired.Text
            Dim cn As New SqlConnection("Connection String")
            Dim cmd As New SqlCommand With {
                .Connection = cn,
                .CommandType = CommandType.Text,
                .CommandText = "Select NumberOfSeats, DriverCallsign From Vehicle"}
            cn.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader
            Do While dr.Read
                If dr.GetString(0) = strSeats Then
                    ComboBox1.Items.Add(dr.GetString(1))
                End If
            Loop
        End Sub
    forgot cn.Close

    Mary

    • Marked as answer by Gary Simpson Friday, November 3, 2017 4:52 PM
    Friday, November 3, 2017 6:58 AM
  • Hi Cherry Bu

    Thank you for getting back too me, You are right about the Radio Button Depending on which on is clicked a text holds a value as a string text.

    Let's  say I have checked Radio Button (4 Seat Vehicle) Then text "4 Seat Vehicle" is put into textbox as a string.

    Now is what I want to Do, Is List All Drivers Driving a (4 SEAT VEHICLE) And a (6 SEAT VEHICLE) in A combo box  By their Call sign Name(cbxDriverCallsign)

    But if I checked the Radio Button (6 SEAT VEHICLE) Then text "6 Seat Vehicle" is put into textbox as a string then I would like the Combo Box to List Drivers  Driving (6 SEAT VEHICLE) And a (8 SEAT VEHICLE)

    Else If I check Radio Button (8 SEAT VEHICLE) Then text "8 Seat Vehicle" is put into textbox as a string then I would like the Combo Box (cbxDriverCallsign) to List Drivers  Driving (8 SEAT VEHICLE ) ONLY

    I hope This Clarifies What I want to Happen

    Kind Regards 

    Gary


    Gary Simpson

    Friday, November 3, 2017 4:02 PM
  • I am assuming that the NumberOfSeats field is a string which will match your text box.
        
    Private Sub FillCombo()
            Dim strSeats = txtVehicleRequired.Text
            Dim cn As New SqlConnection("Connection String")
            Dim cmd As New SqlCommand With {
                .Connection = cn,
                .CommandType = CommandType.Text,
                .CommandText = "Select NumberOfSeats, DriverCallsign From Vehicle"}
            cn.Open()
            Dim dr As SqlDataReader = cmd.ExecuteReader
            Do While dr.Read
                If dr.GetString(0) = strSeats Then
                    ComboBox1.Items.Add(dr.GetString(1))
                End If
            Loop
        End Sub
    forgot cn.Close

    Mary

    Hi Mary

    Thank for getting back too Me Your code works, It will show only the vehicle with the number of seats required I can Live with that...

    Thank you Very Much Mary

    Kind Regards

    Gary


    Gary Simpson

    Friday, November 3, 2017 4:52 PM