“已经有一个开放的DataReader ......”重用或配置数据库连接?
请帮助....当我从Mysql表中选择数据时,它显示“已经有一个与此Connection相关的开放DataReader必须先关闭.vb.net”
Private Sub cmbJobCategoryVisa_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbJobCategoryVisa.SelectedIndexChanged ''" Dim MyCommand As New MySqlCommand("SELECT jobcategorycode FROM jobcategory WHERE jobcategory='" & Me.cmbJobCategoryVisa.SelectedItem & "'", MyConnection) Dim MyReader As MySqlDataReader = MyCommand.ExecuteReader While MyReader.Read If MyReader.HasRows = True Then Me.txtJobCategoryCodeVisa.Text = MyReader("jobcategorycode") End If End While MyReader.Close() MyCommand.Dispose()End Sub
'''在下面的代码执行时,',显示成像错误
Private Sub txtEmpNo_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtEmpNo.Validating Dim MyCommand5 As New MySqlCommand("SELECT * FROM employeesmaster WHERE empno='" & Me.txtEmpNo.Text & "'", MyConnection) Dim MyDataReader5 As MySqlDataReader = MyCommand5.ExecuteReader If MyDataReader5.HasRows = True Then While MyDataReader5.Read Me.txtEmpName.Text = MyDataReader5("name") Me.cmbNationality.Text = MyDataReader5("nationality") Me.cmbJobCategoryVisa.Text = MyDataReader5("jobcategoryvisa") If Not IsDBNull(MyDataReader5("image")) Then Dim ImageData As Byte() = DirectCast(MyDataReader5("image"), Byte()) Dim MemoryStream As New IO.MemoryStream(ImageData) Me.pbxEmpImage.Image = Image.FromStream(MemoryStream) Else Me.pbxEmpImage.Image = Nothing End If End While Else End If MyDataReader5.Close() MyCommand5.Dispose()End Sub
凤凰求蛊