0
Imports System.Data.SqlClient
Public Class F_Contentor
Dim F_Topo As New Form2()
Dim F_Principal As New Form3()
Dim Prof_Ses_Nome As String
Dim Prof_Ses_Id As Integer
Const cs As String = "Data Source=D01PC1\SQLEXPRESS;Initial Catalog=Desinovar;Integrated Security=True"
Public con As New SqlConnection(cs)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Prof_Ses_Nome = Login.prof_Ses_Nome.ToString()
Prof_Ses_Id = Login.prof_Ses_ID
Login.Close()
F_Topo.TopLevel = False
F_Principal.TopLevel = False
Me.Painel_Topo.Controls.Add(F_Topo)
Me.Painel_Main.Controls.Add(F_Principal)
F_Topo.Show()
F_Principal.Show()
F_Topo.CB_Prof.Items.Add(Prof_Ses_Nome)
F_Topo.CB_Prof.SelectedIndex = 0
End Sub
Public Sub Get_Turma()
F_Topo.CB_Turma.Items.Clear()
Using con
Dim sql As String = "select Turma.Nome from Turma,Professores_Turma,Professores where Turma.Id_Turma = Professores_Turma.Id_Turma and Professores_Turma.Id_Professor = Professores.Id_Professor and Professores.Id_Professor ='" & Prof_Ses_Id & "'"
Dim sqlCom As New SqlCommand(sql, con)
con.Open()
Dim dr As SqlDataReader = sqlcom.ExecuteReader()
If dr.HasRows Then
While dr.Read()
F_Topo.CB_Turma.Items.Add(dr.Item(0))
End While
Else
' Aqui faça o que quiser caso não tenha linha '
End If
dr.Close()
End Using
End Sub
Public Sub Get_Disciplinas()
F_Topo.CB_Disciplina.Items.Clear()
Using con
Dim sql As String = "select Disciplinas.Nome from Disciplinas,Turma,Professores_Turma,Professores where Turma.Id_Turma = Professores_Turma.Id_Turma and Professores_Turma.Id_Professor = Professores.Id_Professor and Professores_Turma.Id_Disciplina = Disciplinas.Id_Disciplina and Professores.Id_Professor ='" & Login.prof_Ses_ID & "' and Turma.Nome = '" & F_Topo.CB_Turma.SelectedItem & "'"
Dim sqlCom As New SqlCommand(sql, con)
con.Open()
Dim dr As SqlDataReader = sqlCom.ExecuteReader()
If dr.HasRows Then
While dr.Read()
F_Topo.CB_Disciplina.Items.Add(dr.Item(0))
End While
Else
' Aqui faça o que quiser caso não tenha linha '
End If
dr.Close()
End Using
End Sub
End Class
I have this code and when I run it, it tells me that the variable dr (Sqldatareader) was not closed. At the end of each procedure, always close the variable connection dr. Someone can help me?
only to ensure, after
dr.Close()putsdr = Nothing– WeezHard
Yeah. It doesn’t work :/
– lemario
Strange... the mistake happens in both methods? (
Get_Disciplinas()andGet_Turma()) ?– WeezHard
No. Only in Get_turma(). I have another colleague with the same mistake..
– lemario
after the
While dr.Read(), tries to remove all code inside, and leaves only one message box displaying this content:dr.Item(0).ToStringworks like this?– WeezHard
as in the comments I can not leave code formatted, with reply with a previous solution... I will change as you are giving the feedback
– WeezHard
Ok. It already works if you remove all the code inside the while from the Get_class().
– lemario
But if you put this code: F_top.Cb_class.Items.Add(dr.Item(0)) No longer works again.
– lemario
see my answer
– WeezHard