vb的recordset的open方法执行多条sql语句,单条可以执行了,多条如何执行,用nextrecordset总是出错。请大家帮忙想想办法,或改改程序。谢谢,单条执行程序如下:
Private Sub Command1_Click()
Dim cn As New adodb.Connection
Dim cmd As New adodb.Command
Dim rs As New adodb.Recordset
Dim rs2 As adodb.Recordset '后添加的
Dim a11 As Date
Dim a12 As Integer
a11 = #7/20/2010#
a12 = 13001
Dim j As Integer
Dim path1 As String
Dim path2 As String
Dim sql As String
Dim sql1 As String
path1 = "c:\7月20日"
 path2 = "c:\7月21日"
cn.Open "Provider=OraOLEDB.Oracle.1;User ID=12;password=df;Data Source=192.168.1.32:1521/pdbqz;Persist Security Info=False"
    rs.ActiveConnection = cn
    rs.LockType = adLockOptimistic
    rs.CursorLocation = adUseClient
   sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
  rs.Source = sql
   rs.Open
   Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
    Set rs = Nothing
End
End Sub

解决方案 »

  1.   

    Private Sub Command1_Click()
    Dim cn As New adodb.Connection
    Dim cmd As New adodb.Command
    Dim rs As New adodb.Recordset
    Dim rs2 As adodb.Recordset '后添加的
    Dim a11 As Date
    Dim a12 As Integer
    a11 = #7/20/2010#
    a12 = 13001
    Dim j As Integer
    Dim path1 As String
    Dim path2 As String
    Dim sql As String
    Dim sql1 As String
    path1 = "c:\7月20日"
     path2 = "c:\7月21日"
    cn.Open "Provider=OraOLEDB.Oracle.1;User ID=12;password=df;Data Source=192.168.1.32:1521/pdbqz;Persist Security Info=False"
      rs.ActiveConnection = cn
      rs.LockType = adLockOptimistic
      rs.CursorLocation = adUseClient
      sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
      rs.Source = sql
      rs.Open
      while not rs.eof
         Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
          rs.movenext
      wend
      rs.close
      Set rs = Nothing
    End
    End Sub
      

  2.   

    谢谢,我的意思是想再执行一条sql语句,而不一定读取下一条记录。就是在Call blobtofile(rs.Fields("OBSVALUE"), path1) 后边接着执行一个sql语句。
      

  3.   

    修改一下Private Sub Command1_Click()
        Dim cn As New adodb.Connection
        Dim cmd As New adodb.Command
        Dim rs As New adodb.Recordset
        Dim rs2 As adodb.Recordset '后添加的
        Dim a11 As Date
        Dim a12 As Integer
        a11 = #7/20/2010#
        a12 = 13001
        Dim j As Integer
        Dim path1 As String
        Dim path2 As String
        Dim sql As String
        Dim sql1 As String
        path1 = "c:\7月20日"
        path2 = "c:\7月21日"
        
        cn.Open "Provider=OraOLEDB.Oracle.1;User ID=12;password=df;Data Source=192.168.1.32:1521/pdbqz;Persist Security Info=False"
        rs.ActiveConnection = cn
        rs.LockType = adLockOptimistic
        rs.CursorLocation = adUseClient
        sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
        rs.Source = sql
        rs.Open
        
        While Not rs.EOF
            Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
            rs.movenext
        Wend
        
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
    '    End
    End Sub
      

  4.   

    哈哈。看来还是我没有说清楚。我想执行sql与sql1两条查询语句。现在不知道怎么做。哈哈。
    Private Sub Command1_Click()
        Dim cn As New adodb.Connection
        Dim cmd As New adodb.Command
        Dim rs As New adodb.Recordset
        Dim rs2 As adodb.Recordset '后添加的
        Dim a11 As Date
        Dim a12 As Integer
        a11 = #7/20/2010#
        a12 = 13001
        Dim j As Integer
        Dim path1 As String
        Dim path2 As String
        Dim sql As String
        Dim sql1 As String
        path1 = "c:\7月20日"
        path2 = "c:\7月21日"
        
        cn.Open "Provider=OraOLEDB.Oracle.1;User ID=12;password=df;Data Source=192.168.1.32:1521/pdbqz;Persist Security Info=False"
        rs.ActiveConnection = cn
        rs.LockType = adLockOptimistic
        rs.CursorLocation = adUseClient
        sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
        
       sql2= "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & b11 & "','YYYY-MM-DD') and ITEMID=3124 and STATIONID=" & a12 & "and pointid=1"
            
    rs.Source = sql
        rs.Open
        
        While Not rs.EOF
            Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
            rs.movenext
        Wend
        
        rs.Close
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
    '    End
    End Sub
      

  5.   

    我想同时读数据库中的两条记录,写在两个文件里边。现在可以读一条,写在一个文件里了,想执行第二条sql语句读第二条记录,不知道怎么做了。用nextrecord执行总出错。所以看看有什么好办法。
      

  6.   

    Private Sub Command1_Click()
        Dim cn As New adodb.Connection
        Dim cmd As New adodb.Command
        Dim rs As New adodb.Recordset
        Dim rs2 As adodb.Recordset '后添加的
        Dim a11 As Date
        Dim a12 As Integer
        a11 = #7/20/2010#
        a12 = 13001
        Dim j As Integer
        Dim path1 As String
        Dim path2 As String
        Dim sql As String
        Dim sql1 As String
        path1 = "c:\7月20日"
        path2 = "c:\7月21日"
        
        cn.Open "Provider=OraOLEDB.Oracle.1;User ID=12;password=df;Data Source=192.168.1.32:1521/pdbqz;Persist Security Info=False"
        rs.ActiveConnection = cn
        rs.LockType = adLockOptimistic
        rs.CursorLocation = adUseClient
        
        '第一个
        sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
        rs.Source = sql
        rs.Open
        
        While Not rs.EOF
            Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
            rs.movenext
        Wend
        
        rs.Close
        
        '第二个
        sql = "select * from QZDATA.QZ_312_DYS_02 where STARTDATE=to_date('" & a11 & "','YYYY-MM-DD') and ITEMID=3123 and STATIONID=" & a12 & "and pointid=1"
        rs.Source = sql
        rs.Open
        
        While Not rs.EOF
            Call blobtofile(rs.Fields("OBSVALUE"), path1) '读3123测项的数据
            rs.movenext
        Wend
        
        rs.Close
        
        
        Set rs = Nothing
        cn.Close
        Set cn = Nothing
    '    End
    End Sub
      

  7.   

    好的。我试一下。谢谢jhone99。
      

  8.   

    LZ真不厚道,JHONE99回答了这么久,没看见JHONE99有分。,你既然结的是无满足回复?