本文介绍了如何从localhost中选择所有数据,然后插入服务器网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#这是我的localhost连接字符串
#This is my localhost connectionstring
con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};database=schemalocal;option=0;port=3306;server=localhost;uid=root;pwd=root"
#这是服务器连接字符串
#This is for server connectionstring
con.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};server=192.168.1.1;database=schemanetwork;uid=root;pwd=root;option=0"
#schemalocal中的表格与schemanetwork的值相同
我想从localhost获取数据然后转移到服务器网络
基础查询 - >
#My tables in schemalocal is the same value at schemanetwork
I want to get data from localhost then transfer to server network
basis query ->
Insert into schemanetwork.table1 select * from schemalocal;
推荐答案
Dim LocalCN As New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};database=schemalocal;option=0;port=3306;server=localhost;uid=root;pwd=root" )
Dim ServerCN As New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};server=192.168.1.1;database=schemanetwork;uid=root;pwd=root;option=0")
'for get data from local
LocalCN.open()
Dim adp As New OdbcDataAdapter("SELECT * from schemanetwork.table1", LocalCN)
adp.Fill(dt)
LocalCN.close()
'for insert data to online server
ServerCN.open()
Dim cmd As New OdbcCommand("INSERT INTO schemanetwork.table1(a) values(" & dt.rows(0).item("a").tostring() &")", ServerCN)
cmd.ExecuteNonQuery()
ServerCN.close()
Dim LocalCN As New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};database=schemalocal;option=0;port=3306;server=localhost;uid=root;pwd=root" )
Dim ServerCN As New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};server=192.168.1.1;database=schemanetwork;uid=root;pwd=root;option=0")
'for get data from local
LocalCN.open()
Dim adp As New OdbcDataAdapter("SELECT * from schemanetwork.table1", LocalCN)
adp.Fill(dt)
LocalCN.close()
'for insert data to online server
ServerCN.open()
For i = 0 To dt.Rows.Count - 1
Dim cmd As New OdbcCommand("INSERT INTO schemanetwork.table1(a,b,c) values('" & dt.rows(i).item("a").tostring() &"','" & dt.rows(i).item("b").tostring() &"','" & dt.rows(i).item("c").tostring() &"')", ServerCN)
cmd.ExecuteNonQuery()
Next
ServerCN.close()
这篇关于如何从localhost中选择所有数据,然后插入服务器网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!