sqlstr = "select pzxh,accno,amount,qytypecode into gs_pzxh,acc_no,tax_amount,qylxdm from gspldkinfo where note1=" & num
dbconnect.Execute (sqlstr)
我想把数据从表里查出来放到几个变量里,上面的做法问题在哪里。不对的话应该怎么做??

解决方案 »

  1.   

    查询出来得到一个记录集合
      不是gs_pzxh,acc_no,tax_amount,qylxdm 这么4个数
      要是有10条记录就应该是10 * 4 个数
      

  2.   

    那我要得到gs_pzxh,acc_no,tax_amount,qylxdm 的每一项,该怎么做那?请您教我。
      

  3.   

    使用ADO循环遍历所有记录.    Dim Rs          As New ADODB.Recordset
        Dim SQLStrn     As String
        Dim ConnPrefix  As String
        Dim str(10)     As String    ConnPrefix = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Jet OLEDB:System    database=SYSTEM.MDW;Data Source="    SQLStrn = "SELECT * FROM [gspldkinfo] "
        Rs.Open SQLStrn, ConnPrefix & "001" & ".MDB", _
            ADODB.adOpenStatic, ADODB.adLockReadOnly, ADODB.adCmdText
        
        Do While Not Rs.EOF Then
            str(0) = Rs("gs_pzxh")
            str(1) = Rs("acc_no")
            str(2) = Rs("tax_amount")
            Rs.MoveNext
        Loop
      

  4.   

    根据我的查询条件,每次只会查出一条记录,如何能得到这条记录的每个字段?用junki的方法来做这个工作有点大材小用了,有没有其他简单的方法?
      

  5.   

    sqlstr = "select pzxh,accno,amount,qytypecode into gs_pzxh,acc_no,tax_amount,qylxdm from gspldkinfo where note1=" & num
    ------------------------------------------
    要是你的note1字段不是数值类型的话,需要加两个单引号:sqlstr = "select pzxh,accno,amount,qytypecode into gs_pzxh,acc_no,tax_amount,qylxdm from gspldkinfo where note1='" & num & "'"
      

  6.   

    上面的sql语句还是写错了
    sqlstr = "select pzxh,accno,amount,qytypecode from gspldkinfo where note1='" & num & "'"
    junki(『.NET技术争霸天下』) 的方法还是得用的只要一条记录的话,就不用循环了
      

  7.   

    Dim myRecordset As New ADODB.Recordset
    我是这样连数据库的
        Set dbconnect = New ADODB.Connection
        dbpath = "E:\gs\dabase" & "\pldkdata.mdb;"
        dbstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath
        dbconnect.Open dbstr
    取数据:
        sqlstr = "select pzxh,accno,amount,qytypecode from gspldkinfo where note1='" & num & "'"
       dbconnect.Execute (sqlstr)
            
       gs_pzxh = myRecordset("pzxh")
       acc_no = myRecordset("accno")
       tax_amount = myRecordset("amount")
       retcode = myRecordset("qytypecode")在调试的时候报"在对应所需名称或序号的集合中,未找到项目"?????
      

  8.   

    hank212(Impossible Is Nothing.) 
    我是在提问题,我上面的做法在执行到gs_pzxh = myRecordset("pzxh")就会报"在对应所需名称或序号的集合中,未找到项目"?????请帮我看看