Hola Alex, buenos días:
He ido a los enlaces que me indicaste y no encontré la solución. Después de mucho indagar he logrado que me actualice todos los registros modificados a excepción del primero de la base de datos que no encuentro la manera.
Te paso el código a ver dónde falla.
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.DataRow
Public Class FPTRANSF2
Dim cnn As New OleDb.OleDbConnection
Dim cnnm As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim daf As New OleDb.OleDbDataAdapter
Dim dt As DataTable
Dim dtf As DataTable
Dim ds As DataSet
Dim vffp As DateTime
Dim de As New BindingSource
Public vfs1 As Single
Public vfi1 As Integer
Dim col As Double
Dim col1 As String
Dim col2 As Date
Dim col3 As Integer
Private Sub FPTRANSF2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
vffp = FPTRANSF.vffp
Dim cb As New OleDbCommandBuilder(da)
cnn = New OleDb.OleDbConnection
cnn.ConnectionString = strcon
cnnm = New OleDb.OleDbConnection
cnnm.ConnectionString = strcon
Dim consulta As String
Dim consulta1 As String
If vffp = Nothing Then '> vgfi Then
MsgBox("Fecha no seleccionada ")
Else
Me.B1.Visible = True
Me.B2.Visible = True
MsgBox("Fecha seleccionada " & vffp)
End If
consulta = "SELECT TFACTURASR.VENCIMIENTO, TPROVEEDORES.NOMBRE, " & _
"TFACTURASR.IMPORTE, TFACTURASR.IMPORTET, " & _
"TFACTURASR.FACTURANR, TFACTURASR.FECHAE, " & _
"TFACTURASR.FACTURANE, TFACTURASR.CONCEPTOP, " & _
"TFACTURASR.FECHAP, TFACTURASR.CLAVE " & _
"FROM TPAGO INNER JOIN (TPROVEEDORES INNER JOIN " & _
"TFACTURASR ON TPROVEEDORES.CLAVE = TFACTURASR.CPROVEEDOR) " & _
"ON TPAGO.CLAVE = TFACTURASR.FPAGO " & _
"WHERE (((TPROVEEDORES.NOPAGAR)= FALSE) AND " & _
"((TFACTURASR.NOPAGAR)= FALSE) AND " & _
"((TFACTURASR.IMPORTET)= 0) AND " & _
"((TFACTURASR.FECHAP)<= Datevalue('" & vgfi & "')) AND " & _
"((TFACTURASR.PAGADA)= FALSE) AND " & _
"((TFACTURASR.FPAGO) LIKE '4%') AND " & _
"((TFACTURASR.VENCIMIENTO) = Datevalue('" & vffp & "'))) " & _
"ORDER BY TPROVEEDORES.NOMBRE"
da = New OleDb.OleDbDataAdapter(consulta, cnn)
ds = New DataSet
dt = New DataTable
da.Fill(dt)
ds.Tables.Add(dt)
consulta1 = "SELECT IMPORTET, CONCEPTOP, FECHAP, CLAVE FROM TFACTURASR " & _
"ORDER BY CLAVE"
daf = New OleDb.OleDbDataAdapter(consulta1, cnnm)
dtf = New DataTable
daf.Fill(dtf)
If dt.Rows.Count > 0 Then
preparartransferencia()
Else
MsgBox("sigue")
prepararfichero()
End If
End Sub
Private Sub preparartransferencia()
DG1.DataSource = dt
Dim vmt1 As String
Dim vmt2 As String
Dim vms1 As Single
Dim fila As Integer = 0
While fila <= dt.Rows.Count - 1
vmt1 = DG1.Rows(fila).Cells(1).Value
vmt1 = dt.Rows(fila)(1)
vms1 = 0.0
vmt2 = ""
Do While dt.Rows(fila)(1) = vmt1 And fila <= dt.Rows.Count - 1
vms1 = vms1 + dt.Rows(fila)(2)
If vmt2 = "" Then
vmt2 = dt.Rows(fila)(6)
Else
vmt2 = vmt2 & "," & dt.Rows(fila)(6)
End If
dt.Rows(fila)(8) = dt.Rows(fila)(0)
If fila = dt.Rows.Count - 1 Then
dt.Rows(fila)(3) = vms1
dt.Rows(fila)(7) = vmt2
vfs1 = vfs1 + vms1
Exit While
Else
If fila < dt.Rows.Count - 1 Then
fila = fila + 1
End If
End If
Loop
If fila <= dt.Rows.Count - 1 Then
fila = fila - 1
dt.Rows(fila)(3) = vms1
dt.Rows(fila)(7) = vmt2
vfs1 = vfs1 + vms1
fila = fila + 1
End If
End While
For Each row As DataRow In dt.Rows
If row.RowState = DataRowState.Modified Then
col = row.Item("IMPORTET")
col1 = row.Item("CONCEPTOP").ToString
col2 = row.Item("FECHAP")
col3 = row.Item("CLAVE")
Dim consultam As String
consultam = "UPDATE TFACTURASR SET IMPORTET = ('" & col & "'), " & _
"CONCEPTOP = ('" & col1 & "'), " & _
"FECHAP = Datevalue('" & col2 & "') " & _
"WHERE (CLAVE) = (" & col3 & ") "
Try
If (Not cnnm Is Nothing) Then
cnnm.Close()
End If
cnnm.Open()
Dim cmd As New OleDbCommand(consultam, cnnm)
cmd.ExecuteNonQuery()
dtf.AcceptChanges()
Catch ex As Exception
MessageBox.Show("No ha actualizado bien")
End Try
End If
Next
End Sub
Perdona por mi atrevimiento ya que soy muy novato pero pienso que pudiera ser porque se tratase del último registro del bucle de los modificados.
Te agradecería si puedes revisarlo a ver si hay errores.
Gracias y saludos.