mySql database table sync between Local and Remote using VB.Net

Ashish Dhar 61 Reputation points
2022-02-03T08:38:09.593+00:00

I am trying to update multiple tables from local mysql database to remote mysql database. Following code I am using for insert/update the remote table.
But table is not inserted/updated.

Dim tblStr As String = "select id,tablename from transtablename"
        Dim transtblDT As DataTable = RetDatatable(tblStr, <<Local Connection String>>)
        For i As Integer = 0 To transtblDT.Rows.Count - 1

            Dim ds As New DataSet
            strSql = "select * from " & transtblDT.Rows(i).Item("tablename").ToString 
            Using mcon As New MySqlConnection(<<Local Connection String>>)
                Dim da As New MySqlDataAdapter(strSql, mcon)
                mcon.Open()
                da.Fill(ds, transtblDT.Rows(i).Item("tablename").ToString)
                mcon.Close()
            End Using

            Using mcon As New MySqlConnection(<<Remote Connection String>>)
                Dim da As New MySqlDataAdapter("SELECT * FROM " & transtblDT.Rows(i).Item("tablename").ToString, mcon)
                Dim cb As New MySqlCommandBuilder(da)
                mcon.Open()

                da.Update(ds, transtblDT.Rows(i).Item("tablename").ToString)
                mcon.Close()
            End Using

        Next

Requesting your help how to resolve this issue.

Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
714 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,579 questions
{count} votes

Accepted answer
  1. Viorel 112.5K Reputation points
    2022-02-03T09:16:05.557+00:00

    Before calling da.Update, try executing a loop:

    For j As Integer = 0 To ds.Tables(0).Rows.Count – 1
       ds.Tables(0).Rows(j).SetAdded()
    Next j
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful