Visual Basic.NET - Error There is already an open DataReader associated with this Command which must be closed first

 
Vista:
sin imagen de perfil

Error There is already an open DataReader associated with this Command which must be closed first

Publicado por Nicolas (7 intervenciones) el 01/12/2015 01:09:41
Buenas, tengo el siguiente problema:

En un formulario quiero buscar datos de clientes desde una BD mysql, pero si primero busco uno que no exista, cuando voy a buscar otro por segunda vez pero que si exista me salta el error diciendo que ya tengo un DataReader abierto, revise y no encuentro la razon del mensaje, espero que me puedan ayudar.

Mi codigo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
conexion.Open()
 
Dim sql10 As String
Dim cmd10 As MySqlCommand
Dim rdr10 As MySqlDataReader
 
If Not (IsNumeric(txtDoc.Text)) Or txtDoc.Text = "" Then
	MsgBox("Ingrese un número valido de documento")
	txtDoc.Text = ""
	txtDoc.Focus()
End If
 
If Not (txtDoc.Text = "") Then
	sql10 = "select doc, nombres, apellidos from clientes where doc=" & txtDoc.Text
	cmd10 = New MySqlCommand(sql10, conexion)
	rdr10 = cmd10.ExecuteReader()
 
	If rdr10.Read Then
		txtDoc.Text = rdr10.GetString("doc")
		txtNombres.Text = rdr10.GetString("nombres")
		txtApellidos.Text = rdr10.GetString("apellidos")
		rdr10.Close()
 
	Else
 
		MsgBox("¡El cliente no existe!", MsgBoxStyle.Critical, "")
		txtDoc.Text = ""
		txtDoc.Focus()
 
		rdr10.Close()
 
	End If
End If
 
conexion.Close()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder