实时错误,424
请各位高手帮我检查一下我的下段代码,错误在那里,请指出,不胜感谢.(刚加入,没多少分,请不要见怪)我的目的是,利用VB,将数据库E中的表t_voucher的数据复制添加到数据库C中的表t_voucher,两表的结构属性字段都完全相同.
执行时报错:实时错误,424,要求对象.
Private Sub Command1_Click()
Dim cn1
Dim cn2
Dim rs1
Dim rs2
Set cn1 = New ADODB.Connection
cn1.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=E;Data Source=server"
Set cn2 = New ADODB.Connection
cn2.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=c;Data Source=server"
'Set rs1 = cn1.Execute("select * from e.dbo.t_voucher")
rs1.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=E;Data Source=server"
'Set rs2 = cn2.Execute("select * from c.dbo.t_voucher")
rs2.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=c;Data Source=server"
rs1.MoveFirst
While Not rs1.EOF
rs2.AddNew
rs2(1).Value = rs1(1).Value
rs2(2).Value = rs1(2).Value
rs2(3).Value = rs1(3).Value
rs2(4).Value = rs1(4).Value
rs2(5).Value = rs1(5).Value
rs2(6).Value = rs1(6).Value
rs2(7).Value = rs1(7).Value
rs2(8).Value = rs1(8).Value
rs2(9).Value = rs1(9).Value
rs2(10).Value = rs1(10).Value
rs2(11).Value = rs1(11).Value
rs2(12).Value = rs1(12).Value
rs2(13).Value = rs1(13).Value
rs2(14).Value = rs1(14).Value
rs2(15).Value = rs1(15).Value
rs2(16).Value = rs1(16).Value
rs2(17).Value = rs1(17).Value
rs2(18).Value = rs1(18).Value
rs2(19).Value = rs1(19).Value
rs2(20).Value = rs1(20).Value
rs2(21).Value = rs1(21).Value
rs2(22).Value = rs1(22).Value
rs2(23).Value = rs1(23).Value
rs2(24).Value = rs1(24).Value
rs2(25).Value = rs1(25).Value
rs2(26).Value = rs1(26).Value
rs2(27).Value = rs1(27).Value
rs2(28).Value = rs1(28).Value
rs2(29).Value = rs1(29).Value
rs2(30).Value = rs1(30).Value
rs2(31).Value = rs1(31).Value
rs2.Update
rs1.MoveNext
Wend
rs1.Close
rs2.Close
cn1.Close
cn2.Close
Set rs1 = Nothing
Set rs2 = Nothing
Set cn1 = Nothing
Set cn2 = Nothing
End Sub
--------------------编程问答-------------------- 是不是没有引用ado对象? --------------------编程问答-------------------- 不可能,已经引用了. --------------------编程问答-------------------- 用错误集 Err.Description 显示你的具体错误
从你的代码看
应该是你打开的纪录集是只读属性
不能进行更新操作
呵呵
不过
我没用过 cn2.Execute
一般都用
rs.open (sql)
去打开纪录集 --------------------编程问答-------------------- 如果是我上边所说的问题
你可以改一下纪录集的游标类型
应该就没什么问题了 --------------------编程问答-------------------- 有没有更详细的解决方法,可否提供,先谢了!
补充:VB , 基础类