【问题标题】:SP from SQL Server 2005 is not returning records in recordset (VB6)SQL Server 2005 中的 SP 不返回记录集中的记录 (VB6)
【发布时间】:2010-06-30 11:51:36
【问题描述】:

感谢 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 参数。

数据库表中存在的另一件事记录不为空。

请对此发表你的看法

谢谢

【问题讨论】:

    标签: vb6


    【解决方案1】:

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

    不,它不支持:这意味着默认游标类型不支持 RecordCount 属性。

    作为更好的内容测试,试试:

    Debug.Print RS.GetString
    

    【讨论】:

      【解决方案2】:

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

      set nocount on
      

      在开始过程中,甚至可能在打开连接后作为查询执行。 如果它没有帮助,请尝试简化存储过程,因为某些东西肯定像 创建存储过程为

      set nocount on
      select 1
      

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-23
          • 2012-04-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多