vb执行存储过程为什么没记录返回???

boaosi 2009-05-04 06:10:23
列入:Tb_AA
code username
1 aaa
2 bbb
3 ccc
创建存储过程
create proc pro_AA
as
begin
set nocount on
select * from Tb_AA
set nocount off
end
---- 执行这个存储过程应该是返回三条记录集

现在我用vb去调用
Dim con As New ADODB.Connection
Dim rs2 As New ADODB.Recordset
Dim mycom As New ADODB.Command

StrCon = "Provider=SQLOLEDB.1;Password=" & strPassWord & ";Persist Security Info=True;User ID=" & strUserName & ";Initial Catalog="数据库名";Data Source=."
con.CommandTimeout = 3000
con.ConnectionString = StrCon
con.Open
''''''''数据库连接没问题
Set mycom.ActiveConnection = con
mycom.CommandText = "pro_AA"
mycom.CommandType = adCmdStoredProc
Set rs2 = mycom.Execute("pro_AA")


执行到这里 rs2中应该有三条记录集。。。

可是我在程序中得到rs2的记录集为空???

????
...全文
91 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tcbo 2009-05-07
  • 打赏
  • 举报
回复
用SQL查询分析器执行
pro_AA
看是否有数据?

若有:
Dim DaCn As New ADODB.Connection
Dim DaRs As New ADODB.Recordset
Dim Sql As String

Sql="exec pro_AA"
DaCn.ConnectionString = StrCon
DaCn.CursorLocation = adUseClient
DaCn.open StrCon


DaRs.Open strsql,DaCn,adOpenStatic, adLockReadOnly

===用下面的语句看下,DsRs的数据源SQL
debug.print DaRs.Source


fxgang 2009-05-06
  • 打赏
  • 举报
回复
存储过程
create proc pro_AA
as
begin
set nocount on
select * from Tb_AA
set nocount off
end

set nocount off
不需要
Dim DaCn As New ADODB.Connection
Dim DaRs As New ADODB.Recordset
Dim Sql As String

Sql="exec pro_AA"
DaCn.ConnectionString = StrCon
DaCn.Open
DaRs.CursorLocation = adUseClient
DaRs.Open Sql, DaCn, adOpenStatic, adLockReadOnly
if not DaRs then
......
end if
DaRs.Close
DaCn.Close
Set DaRs = Nothing
Set DaCn = Nothing
prcstar 2009-05-05
  • 打赏
  • 举报
回复
用SQL查询分析器执行
pro_AA
看是否有数据?
Tiger_Zhao 2009-05-05
  • 打赏
  • 举报
回复
好像记得存储过程中必须最后一句是 SELECT 语句,所以两句 set nocount 是不需要的。
boaosi 2009-05-05
  • 打赏
  • 举报
回复
还是不行哦

继续求助!!
chenyanm 2009-05-05
  • 打赏
  • 举报
回复
直接用
Dim con As New ADODB.Connection
Dim rs2 As New ADODB.Recordset

StrCon = "Provider=SQLOLEDB.1;Password=" & strPassWord & ";Persist Security Info=True;User ID=" & strUserName & ";Initial Catalog="数据库名";Data Source=."
con.CommandTimeout = 3000
con.ConnectionString = StrCon
con.Open
''''''''数据库连接没问题
Set rs2 = con.Execute("exec pro_AA")

boaosi 2009-05-05
  • 打赏
  • 举报
回复
试了上面几位的方法 还是没有成功哦


继续请教!!
prcstar 2009-05-05
  • 打赏
  • 举报
回复
Set rs2 = mycom.Execute("pro_AA") '这句可以写为Set rs2 = mycom.Execute,不需要再使用存储过程名称
prcstar 2009-05-05
  • 打赏
  • 举报
回复
CON.CursorLocation = adUseClient'加上这句
CON.Open
penguinhzf 2009-05-05
  • 打赏
  • 举报
回复
我也试过同样的问题,但现在还没法解决.

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧