Olá, sou novo por aqui e gostaria que me ajudassem a resolver um problema com os combobox relacionados.
Sendo o primeiro combo = cbxOperacao
o segundo = cbxSupervisor
e o terceiro = cbxDiretor
O sistema consegue pegar a informação do primeiro combo, mas não puxa as informações do segundo e terceiro.
Segue código:
Private Sub PreencheOperacao()
Dim con As New SqlConnection(strCon)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT ope_id, ope_nome FROM TBcad_operacao"
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
cbxOperacao.ValueMember = "ope_id"
cbxOperacao.DisplayMember = "ope_nome"
cbxOperacao.DataSource = objDs.Tables(0)
End Sub
Private Sub cbxOperacao_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If cbxOperacao.SelectedValue.ToString() <> "" Then
Dim ope_id As Integer = Convert.ToInt32(cbxOperacao.SelectedValue.ToString())
PreencheSupervisor(ope_id)
cbxDiretor.SelectedIndex = 0
End If
End Sub
Private Sub PreencheSupervisor(ByVal ope_id As Integer)
Dim con As New SqlConnection(strCon)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT sup_id, sup_nome FROM TBcad_supervisor WHERE ope_id =@ope_id"
cmd.Parameters.AddWithValue("@ope_id", ope_id)
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
cbxSupervisor.ValueMember = "sup_id"
cbxSupervisor.DisplayMember = "sup_nome"
cbxSupervisor.DataSource = objDs.Tables(0)
End If
End Sub
Private Sub cbxSupervisor_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim sup_id As Integer = Convert.ToInt32(cbxSupervisor.SelectedValue.ToString())
PreencheDiretor(sup_id)
End Sub
Private Sub PreencheDiretor(ByVal sup_id As Integer)
Dim con As New SqlConnection(strCon)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "SELECT dir_id, dir_nome FROM TBcad_diretor WHERE sup_id =@sup_id"
cmd.Parameters.AddWithValue("@sup_id", sup_id)
Dim objDs As New DataSet()
Dim dAdapter As New SqlDataAdapter()
dAdapter.SelectCommand = cmd
con.Open()
dAdapter.Fill(objDs)
con.Close()
If objDs.Tables(0).Rows.Count > 0 Then
cbxDiretor.ValueMember = "dir_id"
cbxDiretor.DisplayMember = "dir_nome"
cbxDiretor.DataSource = objDs.Tables(0)
End If
End Sub
End Class