vb+sql server,ado方式在模块中定义全局变量Option Explicit
Public table1tbr As ADODB.Recordset
Public table2tbr As ADODB.RecordsetPublic table1cmd As ADODB.Command
Public table2cmd As ADODB.CommandPublic Adocn As New ADODB.Connection连接数据库成功后,并打开table1,得到记录集table1tbr。现在想把第一个表中的记录全部放到表2中。表2为空。
Set tablecmd.ActiveConnection = Adocn '错误显示在这里
table1cmd.CommandText = "insert into table2 select * from table1"
Set table2tbr = Table1cCmd.Execute
,运行之后,提示 实时错误 91,对象变量或with变量未设置。如上程序的位置。我定义他们了啊。不知道为什么?调试了一下午了!谢谢各位了!100分相送!

解决方案 »

  1.   

    既然错误是:对象变量或with变量未设置,
    那也只能慢慢找了.
      

  2.   

    Public table1tbr As new ADODB.Recordset
    Public table2tbr As new ADODB.Recordset
    .........
    Public Adocn As New ADODB.Connection
      

  3.   

    set tablecmd1=new adodb.command
      

  4.   

    command对象使用前必须先实例化
      

  5.   

    Set tablecmd.ActiveConnection = Adocn '错误显示在这里
    table1cmd.CommandText = "insert into table2 select * from table1"
    Set table2tbr = Table1cCmd.Execute
    -------->Set tablecmd=new ADODB.Command
    Set tablecmd.ActiveConnection = Adocn '错误应该没有了吧?!
    table1cmd.CommandText = "insert into table2 select * from table1"
    Set table2tbr = Table1cCmd.Execute