模块
Function connect()
con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};server=localhost;database=tablelocal;uid=root;pwd=root;option=0"
con.Open()
End Function
Function Disconnect()
con.Close()
End Function
网络连接模块
Function connectnetwork()
con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};server=192.168.0.1;database=samplenetwork;uid=root;pwd=root;option=0"
con.Open()
End Function
Function Disconnectnetwork()
con.Close()
End Function
Dim sourceConnection As New OdbcConnection(connect())
Dim destinationConnection As New OdbcConnection(connectNetwork())
Dim adapter As New OdbcDataAdapter("SELECT * from local ", sourceConnection)
Dim insertCommand As New OdbcCommand("INSERT INTO network", destinationConnection)
With insertCommand.Parameters
OdbcCommand = New Odbc.OdbcCommand("Insert into network select * from local ", con)
OdbcCommand.ExecuteNonQuery()
End With
adapter.InsertCommand = insertCommand
'Keep the RowState of each row as Added so it is ready to be inserted.'
adapter.AcceptChangesDuringFill = False
Dim table As New DataTable
'Retrieve data from source database.'
adapter.Fill(table)
'Save data to destination database.'
adapter.Update(table)
答案 0 :(得分:0)
只需与数据适配器使用两种不同的连接,例如
Dim sourceConnection As New OdbcConnection("source connection string here")
Dim destinationConnection As New OdbcConnection("destination connection string here")
Dim adapter As New OdbcDataAdapter("SELECT ...", sourceConnection)
Dim insertCommand As New OdbcCommand("INSERT ...", destinationConnection)
With insertCommand.Parameters
'Add parameters here.'
End With
adapter.InsertCommand = insertCommand
'Keep the RowState of each row as Added so it is ready to be inserted.'
adapter.AcceptChangesDuringFill = False
Dim table As New DataTable
'Retrieve data from source database.'
adapter.Fill(table)
'Save data to destination database.'
adapter.Update(table)
答案 1 :(得分:0)
在网络上所有命令和查询都是区分大小写的(对于mysql) 所有的事情都在"" (双引号)必须区分大小写(对于mysql)
也许尝试添加" Protocol = socket;"到连接字符串。
或检查防火墙
有时防火墙没有让它通过
检查This