I want to convert data from Firebird database to Mysql database, so i managed to put the data in the datagridview and after that i managed also to write those data in the Mysql database.
until now everything seems perfect.
I wanted to write in the database only new records.
Imports System.Configuration
Imports MySql.Data
Imports MySql.Data.MySqlClient
Imports System.Data.DataTable
Imports System.Data.SqlClient
Imports System.Data.Odbc
Imports System.Data
Imports System.Data.Odbc.OdbcCommand
Imports System.Data.OleDb
Public Class MainForm
Public conn_odbc As OdbcConnection
Public conn1 As OdbcConnection
Public conn2 As OdbcConnection
Public ConnMysql_protocol As MySqlConnection
Public Sub connection_to_firebird_prod()
Dim str_odbc_prod As String
str_odbc_prod = "DRIVER=Firebird/InterBase(r) driver;UID=****;PWD=****;DBNAME=*****.GDB;"
conn1 = New OdbcConnection(str_odbc_prod)
End Sub
Public Sub production()
Dim str_odbc_prod As String
str_odbc_prod = "DRIVER=Firebird/InterBase(r) driver;UID=****;PWD=****;DBNAME=****.GDB;"
Dim odbc_connection_prod As New OdbcConnection(str_odbc_prod)
Dim odbc_adapter_prod As New OdbcDataAdapter("select ID,NR,HR from FrirebirdTable", odbc_connection_prod)
Dim table_odbc_prod As New DataTable
odbc_adapter_prod.Fill(table_odbc_prod)
DataGridView_production.DataSource = table_odbc_prod
odbc_adapter_prod.Dispose()
Dim mysql_connection_prod As New MySqlConnection("server=localhost;user id=****;database=mysqldatabase")
Dim insert_in_mysql_prod As New MySqlCommand("INSERT INTO `mysqltable` (`ID`, `NR`, `HR`) VALUES (@ID,@NR,@HR)", mysql_connection_prod)
Try
mysql_connection_prod.Open()
Catch exError As MySqlException
End Try
For i As Integer = 0 To DataGridView_production.RowCount - 1 Step +1
insert_in_mysql_prod.Parameters.Add("@ID", MySqlDbType.Int64).Value = DataGridView_production.Rows(i).Cells(0).Value.ToString
insert_in_mysql_prod.Parameters.Add("@NR", MySqlDbType.Int64).Value = DataGridView_production.Rows(i).Cells(1).Value.ToString
insert_in_mysql_prod.Parameters.Add("@HR", MySqlDbType.Int64).Value = DataGridView_production.Rows(i).Cells(2).Value.ToString
insert_in_mysql_prod.ExecuteNonQuery()
Next
mysql_connection_prod.Close()
End Sub
End Class