蛋糕吃了会胖吗:vb中使用SQL SERVER存储过程

来源:百度文库 编辑:高考问答 时间:2024/04/29 06:46:47
以下为vb代码片段

Set cm = New ADODB.Command
Set cm.ActiveConnection = conn
cm.CommandType = 4
cm.CommandText = "getListPage"
cm.Parameters("@page") = 1
cm.Parameters("@pagesize") =20

cm.Execute
m_rowcount = CStr(cm.Parameters("@counts"))
m_pagecount = CLng(m_rowcount) \ m_pagesize + 1
Set rs = cm.Execute() '记录集
while not rs.eof
.
代码
.
rs.movenext
wend
上面程序可以返回m_rowcount值,问题是要执行两次cm.Execute

如改为:

Set cm = New ADODB.Command
Set cm.ActiveConnection = conn
cm.CommandType = 4
cm.CommandText = "getListPage"
cm.Parameters("@page") = 1
cm.Parameters("@pagesize") =20
Set rs = cm.Execute()
m_rowcount = CStr(cm.Parameters("@counts"))
m_pagecount = CLng(m_rowcount) \ m_pagesize + 1
while not rs.eof
.
代码
.
rs.movenext
wend
则m_rowcount 值等于null

各位高手,请赐教!!!!我已经出最高分了。
m_rowcount = rs.Count

不可以改为这个。因为CStr(cm.Parameters("@counts")) 不等于rs.Count

m_rowcount = CStr(cm.Parameters("@counts"))

m_rowcount = rs.Count

-_-!! 我不懂VB啦,看你那么急,就帮帮忙~

定义一个function
public function execute(sql)
public cm
execute = cm.Execute(sql)
end function

Set cm = New ADODB.Command
Set cm.ActiveConnection = conn
cm.CommandType = 4
cm.CommandText = "getListPage"
cm.Parameters("@page") = 1
cm.Parameters("@pagesize") =20
Set rs = Execute(sqlstr)
m_rowcount = CStr(cm.Parameters("@counts"))