Good, I'm doing a screen where I store the payments of some clients, at the moment of inserting, I must put the same client code. I must use the same client id which is the primary key which gave me an error. I could fix it by doing a procedure but now it does not save anything and it does not return an error.
Here the procedure
ALter procedure SP_InsPagosMa3
@CodigoCliente VARCHAR (10),
@CodigoBanco VARCHAR(2),
@MontoTotal float,
@NumPago varchar(20),
@FechaPago datetime,
@FechaRegistro datetime
AS
BEGIN
INSERT INTO PagosManuales (CodigoCliente,CodigoBanco, MontoTotal, NumeroPago,FechaPago,FechaRegistro)
SELECT
CodigoCliente = @CodigoCliente,
CodigoBanco=@CodigoBanco,
MontoTotal=@MontoTotal,
NumeroPago=@NumPago,
FechaPago=@FechaPago,
FechaRegistro=@FechaRegistro
From [CobrosDirectos].[dbo].[PagosManuales]
WHERE CodigoCliente = @CodigoCliente
END.
VB code of my function
Public Function IsnPago(ByVal CodigoCliente As String, ByVal CodigoBanco As String, ByVal MontoTotal As Double, ByVal NumPago As String, ByVal FechaPago As Date, ByVal FechaRegistro As Date) As String
Dim cn As New Data.SqlClient.SqlConnection
Dim cmd As New SqlCommand
Dim Resultado As String
cn.ConnectionString = C.GetAppConfiguracion("CobroDirecto", "ConnCobroDirecto")
Dim Str As String
Str = ""
cn.Open()
Str = "EXEC SP_InsPagosMa3 CodigoCliente,@CodigoBanco,@MontoTotal,@NumPago,@FechaPago,@FechaRegistro"
cmd = New SqlCommand(Str, cn)
With cmd
.Parameters.Add("@CodigoCliente", Data.SqlDbType.VarChar, 10).Value = CodigoCliente
.Parameters.Add("@CodigoBanco", Data.SqlDbType.VarChar, 2).Value = CodigoBanco
.Parameters.Add("@MontoTotal", Data.SqlDbType.Float).Value = MontoTotal
.Parameters.Add("@NumPago", Data.SqlDbType.VarChar, 20).Value = NumPago
.Parameters.Add("@FechaPago", Data.SqlDbType.DateTime).Value = FechaPago
.Parameters.Add("@FechaRegistro", Data.SqlDbType.DateTime).Value = FechaRegistro
.ExecuteNonQuery()
End With
cn.Close()
Resultado = "Pago aplicado"
Return Resultado
End Function
Code of when I call her
protected Sub BtnAplica_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAplica.Click
Dim resultado As String
Dim Seleccion As Boolean = False
For Each RW As GridViewRow In Gvcobranzas.Rows
If CType(RW.Cells(2).FindControl("CheckBox1"), CheckBox).Checked Then
resultado = GM.IsnPago(TxtBuscarCli.Text, dlBnaco.SelectedValue, TxtPagoTotal.Text, TxtNuPago.Text, TxtFePago.Text, TxtFeReg.Text)
Seleccion = True
With lberror
.Visible = True
.Text = resultado
End With
Else
With lberror
.Visible = True
.Text = "Favor de seleccionar las factura a pagar"
End With
End If
Next
CargaGridClientes()
End Sub