SQL Server 2005中的SP不返回记录集中的记录(VB6)

时间:2010-06-30 11:51:37

标签: vb6

感谢dretzlaff17的回复,

我正在给出细节..........

SQL Server 2005中的SP没有返回recordSet(VB6)中的记录,返回的记录是-1。如果使用查询和记录集访问记录,记录集将填充记录。

使用相同的连接字符串。我正确检查了VB6中为命令对象编写的代码没有问题,那有什么不对?

访问SQL Server 2005时是否还有其他事情要做。

我的代码就像

Dim Conn as new ADODB.Connection

Dim RS as new ADODB.RecordSet

Dim CMD as new ADODB.Command

Conn.Open "Connection String" ' Its working

CMD.ActiveConnection = Conn

CMD.CommandType = adCmdStoredProc

CMD.CommandText = "SPName" 

Set RS = CMD.Execute

Debug.Print RS.RecordCount ' /* here result is -1 means CMD is not executing and RS is not filling with records */

and if use

RS.Open "Select query", conn   'then this record set is filling with records.

我还通过将RS(光标)位置值设置到客户端进行检查,SP很简单,只有选择查询存在于SP无I / O参数中。

数据库表中存在的另一个记录不是空的。

关于这个你的想法

由于

3 个答案:

答案 0 :(得分:1)

  

RS.RecordCount'/ *这里的结果是-1   表示CMD没有执行,RS是   没有填写记录

不可以:它表示默认光标类型不支持RecordCount属性。

作为对内容的更好测试,请尝试:

Debug.Print RS.GetString

答案 1 :(得分:0)

你能显示你存储过程的文本吗? VB6是老东西,可能你只需要把

set nocount on

在开始过程中或者甚至可以在打开连接后执行此查询作为查询。 如果它没有帮助尝试简化存储过程的东西肯定是工作的 创建存储过程为

set nocount on
select 1

答案 2 :(得分:0)

如果您想要记录计数,通常最好这样做:

set RS = new ADODB.Recordset
RS.Open cmd, , adOpenDynamic, adLockReadOnly
If Not RS.EOF then Debug.Print RS.RecordCount
RS.Close