Combobox come blank VB.NET with INNER JOIN

Asked

Viewed 167 times

1

I’m having a little problem here and I haven’t found the solution yet, I’m loading data into a combobox using a DATASET from a INNER JOIN done in a database SQL SERVER. Until then it’s okay only that once I get the Cong, I’d like the other combobox to be blank...

I tried to put meucbx.Selectedindex = 0 in Load, I did not succeed

Follows my code


//Listar as Congs listar_Cong vai para o Load


Private Sub listar_Cong()
        Using con As SqlConnection = CONECTA_DB()
            Try
                con.Open()
                Dim str As String = "SELECT * FROM sys_Config WHERE Status = 1"
                Dim cmd As SqlCommand = New SqlCommand(str, con)
                Dim dr As SqlDataReader
                dr = cmd.ExecuteReader
                While dr.Read
                    cbxCong.Items.Add(dr.Item("Nome")).ToString()
                End While
            Catch
               msgbox(Err.description)
            Finally
                con.Close()
            End Try
        End Using
    End Sub

   //Lista os usuarios com o INNER JOIN

  Private Sub listar_USUARIOS()
        Using con As SqlConnection = CONECTA_DB()
            Try
                con.Open()
                Dim str As String = "SELECT * FROM sys_Config" _
                                    & " INNER JOIN sys_Users"_
                                    & " ON (sys_Config .ID_CONG = sys_Users .ID_CONG)" _
                                    & " WHERE sys_Users.Status = 1"
                Dim da As SqlDataAdapter = New SqlDataAdapter(str, con)
                Dim ds As New DataSet
                da.Fill(ds)
                With cbxUsuarios
                    .DisplayMember = "Usuario"
                    .ValueMember = "ID_CONG"
                    .DataSource = ds.Tables(0).DefaultView
                End With
            Catch
                MessageBox.Show(Err.Description)
            End Try
        End Using
    End Sub

2 answers

1

If you just want to clean up the ComboBox:

meucbx.Items.Clear()
  • After the user selects the Cong he comes with the blank combobox with nothing selected... Cong is congregation

  • And that code didn’t solve?

  • With that code there I zero all the combo data.. would like the index at the beginning to be 0 more if I put in the load does not work after requesting search.. it of the problem.. type user selects congregation he already goes and selects the automated user

0


Guys I managed to solve this with an error code block in my system. I thank you for your attempts!

//Era simplesmente locar isso cbxUsuarios.SelectedIndex = 0 //só que eles estava no local errado

Browser other questions tagged

You are not signed in. Login or sign up in order to post.