Tema: consulta
Ver Mensaje Individual
  #23 (permalink)  
Antiguo 31/03/2005, 10:17
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 20 años, 2 meses
Puntos: 1
Pues te cuento que si lo pongo entre while dr.read

me sale este error

ExecuteNonQuery requires an open and available Connection. The connection's current state is Closed.

resalta esta linea Line 109:MyCommand.ExecuteNonQuery()

pero yo abro la conexion antes

dr = mycommand.executereader

MyCommand.Connection.Open()
dr = mycommand.executereader

While dr.read

Dim UpdateCmd As String

If RadioButton1.Checked = true then

UpdateCmd ="update Formulario set Respuesta1 = "& (Ctype(dr("Respuesta1"),Integer) + 1) & " where formulario = 2"

else if
...

end if

MyCommand = New SqlCommand(UpdateCmd, PortalSettings.SqlConnectionString)

Try
MyCommand.ExecuteNonQuery()
Catch Exp As SQLException
If Exp.Number = 2627
Message.InnerHtml = "ERROR: A record already exists with the same primary key"
Else
Message.InnerHtml = "ERROR: El registro no puede crearse, por favor revise los campos para ver si fueron rellenados correctamente" & Exp.Message
End If
Message.Style("color") = "red"
End Try
end while
dr.close

MyCommand.Connection.Close()

End Sub

eso me parece extraño, a caso no es asi que se abre la conexxion?