Show new records added

0

I have a problem, there is a datagridview that imports the records of an excel file, by sending all those records to be saved to the database, it verifies if the record exists, if it does not exist it adds it, if it exists it jumps to the other one registration and so on until the end, what I want to show at the time of completion only the new records that were added to the database in the datagridview

'método guardar

Public Sub Guardar(ByVal dgv As DataGridView, ByVal agregar As SqlCommand, ByVal cuenta As String)
    Dim totalreg As Integer = 0
    Dim totalgra As Integer = 0
    Try
        'recorriendo el datagridview
        For Each fila In dgv.Rows
            'asignando los valores de cada celda de la fila que se está recorriendo
            Dim monto As Double = 0
            Dim fecha As String = ""
            Dim referencia As String = ""
            Dim descripcion As String = ""
            Dim credito As String = ""
            fecha = fila.Cells("F1").Value
            referencia = fila.Cells("F2").Value
            descripcion = fila.Cells("F3").Value
            credito = fila.Cells("F4").Value
            'verificando si el registro existe
            If Not ExisteRegistro(cuenta, referencia) Then
                'limpiando los parámetros
                agregar.Parameters.Clear()
                'asignando los valores obtenidos de la fila a cada parámetro correspondiente
                agregar.Parameters.AddWithValue("@cuenta", cuenta)
                agregar.Parameters.AddWithValue("@fecha", Convert.ToDateTime(fecha))
                agregar.Parameters.AddWithValue("@referencia", referencia)
                agregar.Parameters.AddWithValue("@descripcion", descripcion)
                monto = convertirDolares(fecha, CDbl(credito))
                agregar.Parameters.AddWithValue("@credito", credito)
                agregar.Parameters.AddWithValue("@estado", 1)
                'ejecutando la consuita
                agregar.ExecuteNonQuery()
                totalgra = totalgra + 1
            Else
                totalreg = totalreg + 1
                Continue For
            End If
        Next
        MsgBox("Se grabaron " + CStr(totalreg) + " transacciones y " + CStr(totalgra) + " estaban repetidos")
    Catch ex As Exception
        MsgBox("Error debido a " + ex.ToString)
    Finally
        con.Close()
    End Try
End Sub
    
asked by Mario Antonio Ruiz Carrillo 11.11.2017 в 17:10
source

1 answer

0

A quick solution to show the new records would be that when you detect that it does not exist and register it, save that record in a list and at the end of the verification process, send that information to your DataGridView that you saved from what were really your new records.

I recommend that you edit your question and adapt that code to visualize it in a better way, I hope it is helpful, Regards.

    
answered by 11.11.2017 в 20:25