我的数据库在模块中连接了,可是在另外一个窗体中想使用command对象定义好sql语句查询,以便能够显示在Flexgrid当中,可是总是报错,请高手指教要如何使用,急!

解决方案 »

  1.   

    Set commStudentMove = New ADODB.Command
               Set cnnStudentMove = New ADODB.Connection
               '设置连接属性
               cnnStudentMove.ConnectionString = "数据库连接字符串"
               'cnnStudentMove.CursorLocation = adUseServer
               cnnStudentMove.Open
               
               '设置Command对象
               Set commStudentMove.ActiveConnection = cnnStudentMove
               commStudentMove.CommandText = "select * from  表名"
    commStudentMove.CommandType = adCmdText
              Set rsStudentMove = commStudentMove.Execute
              rsStudentMove.Close
              rsStudentMove.LockType = adLockBatchOptimistic
              rsStudentMove.Open