VB6 从记录集中插入 table
VB6 insert into table from Recordset
一览一览table
两者具有真正相同的列
但他们在不同的服务器
我想做的是下面这样
cn1.ConnectionString = "Server1"
cn2.ConnectionString = "Server2"
sql = "SELECT * FROM VIEW"
Set rs.1ActiveConnection = cn1
rs1.Open sql, cn1
sql = "INSERT INTO table SELECT * FROM view"
cn2.Execute (sql)
我可以通过cn1访问查看,但是table通过cn2
所以这做不到
我想知道怎么做
table和view完全一样
我搜索了很多,但没有适合我的例子
我认为有两种方法可以做到
正在将记录集插入 table 或将每个字段插入另一个
简单的例子会很有帮助谢谢
这是行不通的,因为即使您是将记录从第一台服务器拉入记录集中,您也是在尝试直接从视图中插入,而不是从记录集中插入。
您可以遍历您的记录集,然后将记录一条一条地插入到另一个数据库中,但这需要很多次往返并且非常慢。更好的方法是使用 UpdateBatch
一次性从记录集中插入。基本思路如下:
cn1.ConnectionString = "Server1"
cn2.ConnectionString = "Server2"
sql = "SELECT * FROM VIEW"
Set rs.ActiveConnection = cn1
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient 'you need a client-side recordset
rs1.Open sql, cn1, adLockBatchOptimistic 'you need to set the locktype to this
Set rs.ActiveConnection = cn2 'now you're connecting your recordset to the other server
rs.UpdateBatch 'and updating the database all in one batch
这应该让你开始。
一览一览table
两者具有真正相同的列
但他们在不同的服务器
我想做的是下面这样
cn1.ConnectionString = "Server1"
cn2.ConnectionString = "Server2"
sql = "SELECT * FROM VIEW"
Set rs.1ActiveConnection = cn1
rs1.Open sql, cn1
sql = "INSERT INTO table SELECT * FROM view"
cn2.Execute (sql)
我可以通过cn1访问查看,但是table通过cn2
所以这做不到
我想知道怎么做
table和view完全一样
我搜索了很多,但没有适合我的例子
我认为有两种方法可以做到
正在将记录集插入 table 或将每个字段插入另一个
简单的例子会很有帮助谢谢
这是行不通的,因为即使您是将记录从第一台服务器拉入记录集中,您也是在尝试直接从视图中插入,而不是从记录集中插入。
您可以遍历您的记录集,然后将记录一条一条地插入到另一个数据库中,但这需要很多次往返并且非常慢。更好的方法是使用 UpdateBatch
一次性从记录集中插入。基本思路如下:
cn1.ConnectionString = "Server1"
cn2.ConnectionString = "Server2"
sql = "SELECT * FROM VIEW"
Set rs.ActiveConnection = cn1
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient 'you need a client-side recordset
rs1.Open sql, cn1, adLockBatchOptimistic 'you need to set the locktype to this
Set rs.ActiveConnection = cn2 'now you're connecting your recordset to the other server
rs.UpdateBatch 'and updating the database all in one batch
这应该让你开始。