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
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
Set rst = conn.Execute(sql)
Text1.Text = rst("cnt") rem 这句是失败的
-----------------
因为记录集中没有CNT这列
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)就可以了