Zdravím vás a zároveň prosím o radu lebo si s tým už neviem pomôcť.
Mám formulár na ktorom sa mi nachádzajú 3 comboboxy, ktoré selektujú dáta z DB a sú na seba previazané.
Samé o sebe fungujú na iných formulároch.
Na tom istom formulári sa nachádza datagrid, ktorí tiež selektuje dáta z DB ale iných tabuliek.
Problém je v tom, že ak sa oba tieto nástroje nachádzajú na jednom formulári, funguje mi IBA datagrid a comboboxi sú prázdne - bez dát.
Neprogramujem dlho, dostala som úlohu v práci musím sa s ňou popasovať. Ďakujem za rady.
Public Class Prijem_vzorky
Dim conn_command As SqlClient.SqlCommand
Dim selektnute_meno As String
Dim sqlda As SqlClient.SqlDataAdapter
Dim sqldsVZORKAR As DataSet
Dim oznaceny_datum As Date
Dim VzorkaDS As DataSet = New DataSet
Dim Vzorku_priniesol As String
Dim Cas_prinesenia As Date
Dim sqldsSKUP As DataSet ''
Dim sqldsPODSKUP As DataSet ''
Dim sqldsPRODUKT As DataSet ''
Private Property IDUZIV As Integer
Private Property selekt_IDuziv As String
Private Property selekt_edit_prihlasmeno As String
''!!!!!CAST LOAD!!!
Private Sub Prijem_vzorky_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' 'TODO: This line of code loads data into the 'CATDataSet2.Uzivatelia' table. You can move, or remove it, as needed.
Me.UzivateliaTableAdapter1.Fill(Me.CATDataSet2.Uzivatelia)
' naplnenie datagridu
DataGridView2.DataSource = VzorkaDS.Tables(0)
' naplnenie combobox1
sqlda = New SqlClient.SqlDataAdapter("select id_skup, 'SKUPINA: '+skup_nazov as nazov from cis_skup where skup_aktualne = 1 order by skup_poradie asc", DBconn.DBCONN)
Try
sqlda.Fill(sqldsSKUP)
Catch ex As Exception
MessageBox.Show("chyba v DB" + vbCrLf + ex.Message)
End Try
ComboBox1.DataSource = sqldsSKUP.Tables(0)
ComboBox1.ValueMember = "id_skup"
ComboBox1.DisplayMember = "nazov"
End Sub
''!!!!!!!!!!!!!!!!!DATAGRID - výplň labelov!!!!!!!!!!!!!
Private Sub DataGridView2_CellDoubleClick_1(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView2.CellDoubleClick
Me.Vypln_vzorkara(DataGridView2.Rows(e.RowIndex).Cells("ID_uziv").Value)
End Sub
Public Sub Vypln_vzorkara(ByVal index As Integer)
'zistenie, na ktorý riadok bolo kliknuté je podla ID_uzivatela, lebo ID sa nemeni
IDUZIV = index
selekt_IDuziv = (New SqlClient.SqlCommand("SELECT [ID_uziv] FROM [CAT].[dbo].[Uzivatelia] where id_uziv = " + IDUZIV.ToString(), DBconn.DBCONN).ExecuteScalar()).ToString()
'Vypln labelu vzorkár, z dvojkliku na meno v datagride
Label5.Text = (New SqlClient.SqlCommand("SELECT [Meno] FROM [CAT].[dbo].[Uzivatelia] where id_uziv = " + IDUZIV.ToString(), DBconn.DBCONN).ExecuteScalar()).ToString() + " " + (New SqlClient.SqlCommand("SELECT [Priezvisko] FROM [CAT].[dbo].[Uzivatelia] where id_uziv = " + IDUZIV.ToString(), DBconn.DBCONN).ExecuteScalar()).ToString()
'Vypln aktuálneho času a dátumu prinesenia vzorky
Label4.Text = Now
selekt_edit_prihlasmeno = Label4.Text
Me.Show()
End Sub
''!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
''!!!COMBOBOX!!!
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
If ComboBox1.SelectedIndex >= 0 Then
sqldsPODSKUP.Clear()
Dim selectedItem = ComboBox1.SelectedItem
Dim selectedItemValue As String = sqldsSKUP.Tables(0).Rows(ComboBox1.SelectedIndex)(0)
sqlda = New SqlClient.SqlDataAdapter("select id_podskup,'PODSKUPINA: '+nazov as nazov from cis_podskup where id_skup = " + selectedItemValue + " and aktualne = 1 order by poradie asc", DBconn.DBCONN)
Try
sqlda.Fill(sqldsPODSKUP)
Catch ex As Exception
MessageBox.Show("chyba v DB" + vbCrLf + ex.Message)
End Try
ComboBox2.DataSource = sqldsPODSKUP.Tables(0)
ComboBox2.ValueMember = "id_podskup"
ComboBox2.DisplayMember = "nazov"
End If
If ComboBox2.SelectedIndex >= 0 Then
sqldsPRODUKT.Clear()
Dim selectedItemSKUP = ComboBox1.SelectedItem
Dim selectedItemValueSKUP As String = sqldsSKUP.Tables(0).Rows(ComboBox1.SelectedIndex)(0)
Dim selectedItemPODSKUP = ComboBox2.SelectedItem
Dim selectedItemValuePODSKUP As String = sqldsPODSKUP.Tables(0).Rows(ComboBox2.SelectedIndex)(0)
sqlda = New SqlClient.SqlDataAdapter("select ID_prod, 'PRODUKT: '+nazov as nazov from cis_prod where id_skup = " + selectedItemValueSKUP + " and ID_podskup = " + selectedItemValuePODSKUP + " and Aktualne = 1 ", DBconn.DBCONN)
Try
sqlda.Fill(sqldsPRODUKT)
Catch ex As Exception
MessageBox.Show("chyba v DB" + vbCrLf + ex.Message)
End Try
ComboBox3.DataSource = sqldsPRODUKT.Tables(0)
ComboBox3.ValueMember = "ID_prod"
ComboBox3.DisplayMember = "nazov"
End If
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
If ComboBox2.SelectedIndex >= 0 Then
sqldsPRODUKT.Clear()
Dim selectedItemSKUP = ComboBox1.SelectedItem
Dim selectedItemValueSKUP As String = sqldsSKUP.Tables(0).Rows(ComboBox1.SelectedIndex)(0)
Dim selectedItemPODSKUP = ComboBox2.SelectedItem
Dim selectedItemValuePODSKUP As String = sqldsPODSKUP.Tables(0).Rows(ComboBox2.SelectedIndex)(0)
sqlda = New SqlClient.SqlDataAdapter("select ID_prod, nazov from cis_prod where id_skup = " + selectedItemValueSKUP + " and ID_podskup = " + selectedItemValuePODSKUP + " and Aktualne = 1 ", DBconn.DBCONN)
Try
sqlda.Fill(sqldsPRODUKT)
Catch ex As Exception
MessageBox.Show("chyba v DB" + vbCrLf + ex.Message)
End Try
ComboBox3.DataSource = sqldsPRODUKT.Tables(0)
ComboBox3.ValueMember = "ID_prod"
ComboBox3.DisplayMember = "nazov"
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs)
Form2.Show()
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Form2.Show()
End Sub
End Class