Private Sub cmdTest_Click()
    Dim conn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    conn.CursorLocation = adUseClient
    Dim connstr As String
    connstr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=SALE;Data Source=PC\BULLET"
    conn.Open connstr
    Dim sql As String
    sql = "select barcode,itemclass,itemname From allstorage where itemclass='烟' compute count(barcode)"
    Set rst = conn.Execute(sql)
    Text1.Text = rst("cnt") rem 这句是失败的
End Sub

解决方案 »

  1.   

    sql = "select barcode,itemclass,itemname From allstorage where itemclass='烟' compute count(barcode)"
    Set rst = conn.Execute(sql)
    Text1.Text = rst("cnt") rem 这句是失败的
    -----------------
    因为记录集中没有CNT这列
      

  2.   

    楼上兄弟,其实我们可以利用ado能返回多纪录集,所以使用rst.nextrecordset.fields(0)就返回了该值了
     sql = "select barcode,itemclass,itemname From allstorage where itemclass='烟';select * from t1 where f1>10;select * from t2 where f2 like 'me%'"
    这样的查询一样可以一次查询就能直接返回所需要查询的纪录集
    调用的时候使用rst.nextrecordset(0):rst.nextrecordset(1):rst.nextrecordset(2)就可以了