Autor Tema: Mostrar los nuevos registros agregados  (Leído 1765 veces)

0 Usuarios y 1 Visitante están viendo este tema.

marioruiz

  • Bit
  • Mensajes: 9
  • Reputación: +0/-0
    • Ver Perfil
Mostrar los nuevos registros agregados
« en: Noviembre 11, 2017, 01:03:51 pm »
Hola, gracias de antemano, tengo un inconveniente, hay un datagridview que importa los registros de un archivo de excel, al mandar todos esos registros a guardar a la base de datos, verifica si existe el registro, si no existe lo agrega, si existe salta al otro registro y así sucesivamente hasta finalizar, lo que deseo que al momento de finalizar me muestre únicamente los registros nuevos que se agregaron a la base de datos en el 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

javierjava

  • Kilobyte
  • **
  • Mensajes: 69
  • Reputación: +6/-0
    • Ver Perfil
Re:Mostrar los nuevos registros agregados
« Respuesta #1 en: Noviembre 14, 2017, 12:55:24 pm »
Que tal aquí te dejo un ejemplo de como lo podrías hacer

https://www.4shared.com/zip/k67jFYZica/Ejemplo.html

espero que te sirva



marioruiz

  • Bit
  • Mensajes: 9
  • Reputación: +0/-0
    • Ver Perfil
Re:Mostrar los nuevos registros agregados
« Respuesta #2 en: Noviembre 14, 2017, 07:39:52 pm »
Muchas gracias por el aporte