Visual Basic.NET - La conversión del tipo DBNull en el tipo Double no es válida

 
Vista:
sin imagen de perfil

La conversión del tipo DBNull en el tipo Double no es válida

Publicado por Claudio (1 intervención) el 21/03/2014 06:50:16
Hola comunidad. Les hago una consulta, al querer agregar un cliente me sale el error "La conversión del tipo DBNull en el tipo Double no es válida" y ya no se por donde buscar. Les pego el codigo de la clase y del formulario para ver si me pueden dar una mano.

Clase: (les paso el codigo que utilizo):

Public Function Agregar(ByVal Tran As SqlTransaction, _
ByVal Apellido As String, _
ByVal Nombre As String, _
ByVal RazonSocial As String, _
ByVal Fantasia As String, _
ByVal Id_CategoriaIVA As Integer, _
ByVal CUIT As String, _
ByVal Id_CategoriaIIBB As Integer, _
ByVal NroIIBB As String, _
ByVal Id_Pais As Integer, _
ByVal Id_Provincia As Integer, _
ByVal Id_Localidad As Integer, _
ByVal Id_Calle As Integer, _
ByVal Calle As String, _
ByVal Nro As Integer, _
ByVal Piso As String, _
ByVal Dpto As String, _
ByVal Telefono As String, _
ByVal Celular As String, _
ByVal Fax As String, _
ByVal Mail As String, _
ByVal Web As String, _
ByVal Contacto As String, _
ByVal FechaAlta As Date, _
ByVal Observaciones As String, _
ByVal Id_CategoriaCliente As Integer, _
ByVal Estado As Integer) As Double

Try

Return SqlHelper.ExecuteScalar(Tran, "Clientes_Agregar", Apellido, Nombre, RazonSocial, Fantasia, Id_CategoriaIVA, _
CUIT, Id_CategoriaIIBB, NroIIBB, Id_Pais, Id_Provincia, Id_Localidad, Id_Calle, _
Calle, Nro, Piso, Dpto, Telefono, Celular, Fax, Mail, Web, Contacto, FechaAlta, _
Observaciones, Id_CategoriaCliente, Estado)

Catch ex As System.Exception
Throw ex
End Try

End Function


Formulario: (Funcion Acepto)

Private Sub Acepto()


Dim oObjeto As New Clientes
Dim oObjeto2 As New ClientesHistoria

Dim resultado As Double

Try

IniciaTransaccion()

Select Case Me.Estado

Case FormEstado.eAgregar
'
resultado = oObjeto.Agregar _
(transaccion, _
txtApellido.Text, _
txtNombre.Text, _
txtRazonSocial.Text, _
txtFantasia.Text, _
CategoriasIVACtrl1.SelectedValue, _
txtCUIT.Text.ToString, _
CategoriasIIBBCtrl1.SelectedValue, _
txtNroIIBB.Text, _
PaisesCtrl1.SelectedValue, _
ProvinciasCtrl1.SelectedValue, _
LocalidadesCtrl1.SelectedValue, _
CallesCtrl1.SelectedValue, _
txtCalle.Text, _
txtNro.Text, _
txtPiso.Text, _
txtDpto.Text, _
txtTelefono.Text, _
txtCelular.Text, _
txtFax.Text, _
txtMail.Text, _
txtWeb.Text, _
txtContacto.Text, _
DateTimePicker1.Value, _
txtObservaciones.Text, _
CategoriasClienteCtrl1.SelectedValue, _
EstadosCtrl1.SelectedValue)

oObjeto2.Agregar(transaccion, _
txtID.Text, _
"ALTA DE CLIENTE", _
"CLIENTE DADO DE ALTA EN EL SISTEMA", _
FechaHoraServidor, _
G_ID_Usuario, _
SingletonEstado("CLIENTESHISTORIA", "ACTIVO"))

FinalizaTransaccion()

MsgBox("Se agregó el Cliente " & resultado, MsgBoxStyle.Information, G_NombreEmpresa)
Me.Estado = FormEstado.eVacio

Case FormEstado.eEdicion

oObjeto.Modificar(transaccion, _
txtID.Text, _
txtApellido.Text, _
txtNombre.Text, _
txtRazonSocial.Text, _
txtFantasia.Text, _
CategoriasIVACtrl1.SelectedValue, _
txtCUIT.Text, _
CategoriasIIBBCtrl1.SelectedValue, _
txtNroIIBB.Text, _
PaisesCtrl1.SelectedValue, _
ProvinciasCtrl1.SelectedValue, _
LocalidadesCtrl1.SelectedValue, _
CallesCtrl1.SelectedValue, _
txtCalle.Text, _
txtNro.Text, _
txtPiso.Text, _
txtDpto.Text, _
txtTelefono.Text, _
txtCelular.Text, _
txtFax.Text, _
txtMail.Text, _
txtWeb.Text, _
txtContacto.Text, _
DateTimePicker1.Value, _
txtObservaciones.Text, _
CategoriasClienteCtrl1.SelectedValue, _
EstadosCtrl1.SelectedValue)

oObjeto2.Agregar(transaccion, _
txtID.Text, _
"MODIFICACION DE CLIENTE", _
"CLIENTE MODIFICADO EN EL SISTEMA", _
FechaHoraServidor, _
G_ID_Usuario, _
SingletonEstado("CLIENTESHISTORIA", "ACTIVO"))

FinalizaTransaccion()

MsgBox("Se modificó el Cliente", MsgBoxStyle.Information, G_NombreEmpresa)
Me.Estado = FormEstado.eVacio

Case FormEstado.eEliminar

FinalizaTransaccion()

End Select

Catch

Dim oObjeto3 As New ErrorLogs

Select Case Me.Estado

Case FormEstado.eAgregar

CancelaTransaccion()

oObjeto3.Agregar(FechaHoraServidor, _
G_NombreFormulario, _
"Acepto", _
"ERROR AL AGREGAR CLIENTE", _
G_NombreUsuario)


MsgBox("Ocurrió un error al Agregar - " & vbCrLf & _
vbCrLf & _
Err.Description, MsgBoxStyle.Critical, G_NombreEmpresa)

Case FormEstado.eEdicion

CancelaTransaccion()

oObjeto3.Agregar(FechaHoraServidor, _
G_NombreFormulario, _
"Acepto", _
"ERROR AL MODIFICAR CLIENTE", _
G_NombreUsuario)

MsgBox("Ocurrió un error al Modificar - " & vbCrLf & _
vbCrLf & _
Err.Description, MsgBoxStyle.Critical, G_NombreEmpresa)

Case FormEstado.eEliminar

CancelaTransaccion()

oObjeto3.Agregar(FechaHoraServidor, _
G_NombreFormulario, _
"Acepto", _
"ERROR AL ELIMINAR CLIENTE", _
G_NombreUsuario)

MsgBox("Ocurrió un error al Eliminar - " & vbCrLf & _
vbCrLf & _
Err.Description, MsgBoxStyle.Critical, G_NombreEmpresa)

End Select

oObjeto3 = Nothing

Finally

oObjeto = Nothing
oObjeto2 = Nothing

End Try

End Sub


Al querer ejecutar Resultado=oObjeto.agregar me salta al catch y me muestra ese error.

Si necesitan mas datos del codigo me lo piden. Gracias.
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
Imágen de perfil de Carlos Javier
Val: 19
Ha aumentado su posición en 5 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

La conversión del tipo DBNull en el tipo Double no es válida

Publicado por Carlos Javier (34 intervenciones) el 22/03/2014 02:23:34
Hola,
Mira lo que está pasando es que tienes un resultado Null que quieres pasar a Double, normalmente esto me ocurre cuando el valor que voy a convertir a Double es nulo o Null.

Me imagino que ese es tu caso, ya que estás ejecutando una función para agregar un registro.

Yo pondría un paro (break) justo antes de ejecutar la función donde se muestra el error y vería el contenido de los parámetros de la función (pasando el puntero sobre cada variable) y en aquel que me muestre dos llaves {}, en ves de un valor, es el causante del error.

Saludos y me cuentas como te va.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar