Soy algo nuevo en VB, ya lo revise y no veo algún detalle, talvez estoy dejando pasar algo pero no se que es.
Al momento de ejecutar el programa, arroja un error de referencia a objeto no establecida
Estos son mis códigos:
Public Sub btnSaveSaldoFavor_Click(sender As Object, e As EventArgs) Handles btnSaveSaldoFavor.Click
Try
If txtObservacionSaldoFavor.Text = "" Or txtSaldoFavor.Text = "" Then
MuestraMensaje("El Campo Observacion No Puede Estar Vacio", "Error", "Error")
ElseIf MessageBox.Show("¿Sus datos son correctos?", "Agregar", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = DialogResult.OK Then
Dim Saldo As Decimal = Decimal.Parse(txtSaldoFavor.Text())
Dim Observacion As String = txtObservacionSaldoFavor.Text()
Dim Res As Integer = InsertaSaldosAFavor(1, _IdCliente, Saldo, _FolioOperacion, Observacion)
MessageBox.Show("Registro Generado con Exito", "Exito")
Me.Close()
End If
Catch ex As Exception
MuestraMensaje("Error al Agregar el registro: " & ex.Message, String.Empty, "Error")
End Try
End Sub
Imports System.Configuration.ConfigurationManager
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Public Module mdlInsertSaldosAFavor
Private InsertCommand As SqlCommand
Private SqlConSaldos As SqlConnection
Public Function InsertaSaldosAFavor(Accion As Integer, fiIdCliente As Integer, fnSaldo
As Decimal, _
fvFolio As String, fvObservacion As String) As
Integer
Dim Res As Integer = 0
Try
''Dim SqlConSaldos As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Saldos_A_Favor").ConnectionString)
InsertCommand = New SqlCommand("SP_SaldosAFavorManager", SqlConSaldos)
InsertCommand.CommandType = CommandType.StoredProcedure
InsertCommand.Parameters.AddWithValue("@Accion", Accion)
InsertCommand.Parameters.AddWithValue("@fiIdCliente", fiIdCliente)
InsertCommand.Parameters.AddWithValue("@fnSaldo", fnSaldo)
InsertCommand.Parameters.AddWithValue("@fvFolio", fvFolio)
InsertCommand.Parameters.AddWithValue("@fvObservacion", fvObservacion)
SqlConSaldos.Open()
Res = InsertCommand.ExecuteNonQuery()
SqlConSaldos.Close()
SqlConSaldos.Dispose()
Catch ex As Exception
Throw New Exception("Error,Al Insertar Saldo A Favor" & ex.Message)
End Try
Return Res
End Function
End Module
El error aparece en la linea comentada: Dim SqlConSaldos As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("Saldos_A_Favor").ConnectionString)