“已经有一个开放的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
2 回答
凤凰求蛊
TA贡献1825条经验 获得超4个赞
Plutonix ,,,这个编码非常好....你可以将此代码转换为Mysql连接...我的连接字符串在下面.. Dim MyConnection As New MySqlConnection("Server=localhost;User=root;Database=officeone;port=3306;Password=123456;")
- 2 回答
- 0 关注
- 422 浏览
添加回答
举报
0/150
提交
取消