ODBC API的SQLGetStmtAttr函数,实现了结果集当前游标所在行书签与行号获取
m_retcode=::SQLGetStmtAttr(m_hstmt,SQL_ATTR_ROW_NUMBER,(PTR)&dwRowNumber,0,NULL);我用这个函数的时候,无论游标在哪里dwRowNumber总是等于0,不知道为什么

解决方案 »

  1.   

    The SQLGetStmtOption function returns the current setting of options that are specified in SQLSetStmtOption plus a couple of additional flags. SQL_ROW_NUMBER specifies the number of the current row in the entire results set. This option is supported for Keyset and Static cursors; otherwise, 0 is returned.大家参考一下这个
      

  2.   

    SQLGetStmtAttr(m_hStmt, SQL_ATTR_QUERY_TIMEOUT, (SQLPOINTER)&lTimeOut, SQL_IS_UINTEGER, &dummy); 
    =========================================
    晕,你那个参数(第三个)好象显示关于超时的。没超时就返回0。
    我的API参考上没看到这个函数,我根据虚参的名字是这么判断的...
    不知道这个解答你满意不?
      

  3.   

    第四个参数换成SQL_IS_UINTEGER试一下
      

  4.   

    SQLGetStmtAttr(m_hstmt,SQL_ATTR_ROW_NUMBER,(PTR)&dwRowNumber,0,NULL);
    msdn解释当第二个参数为SQL_ATTR_ROW_NUMBER等几个参数时,将忽略掉4,5参数
      

  5.   

    This option is supported for Keyset and Static cursors; otherwise, 0 is returned.
    大家看看着句,我估计是数据库属性要改一下
      

  6.   

    不需要修改数据库属性
    创建STMT是,修改游标为静态游标就行了,使用SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR,(SQLPOINTER)SQL_CURSOR_STATIC,0)设置
      

  7.   

    SQL_ATTR_CURSOR 未声明,SQL_ATTR_CURSOR_TYPE我就用了这个,但是SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR,(SQLPOINTER)SQL_CURSOR_STATIC,0)返回-1且还是未得到
      

  8.   

    This option is supported for Keyset and Static cursors; otherwise, 0 is returned.
    //只支持键集游标和静态游标,否则返回0
      

  9.   

    SQLGetStmtAttr() returns the current setting of a statement attribute. 
    Unicode equivalent: 
    This function can also be used with the Unicode character set. The corresponding Unicode function is SQLGetStmtAttrW(). Refer to Unicode functions (CLI) for information on ANSI to Unicode function mappings. 
    Syntax 
    SQLRETURN   SQLGetStmtAttr   (SQLHSTMT          StatementHandle,
                                  SQLINTEGER        Attribute,
                                  SQLPOINTER        ValuePtr,
                                  SQLINTEGER        BufferLength,
                                  SQLINTEGER        *StringLengthPtr); Function arguments Table 76. SQLGetStmtAttr arguments Data type  Argument  Use  Description  
    SQLHSTMT  StatementHandle  input  Statement handle.  
    SQLINTEGER  Attribute  input  Attribute to retrieve.  
    SQLPOINTER  ValuePtr  output  Pointer to a buffer in which to return the value of the attribute specified in Attribute.  
    SQLINTEGER  BufferLength  input  If Attribute is an ODBC-defined attribute and ValuePtr points to a character string or a binary buffer, this argument should be the length of *ValuePtr. If Attribute is an ODBC-defined attribute and *ValuePtr is an integer, BufferLength is ignored. 
    If Attribute is a DB2 CLI attribute, the application indicates the nature of the attribute by setting the BufferLength argument. BufferLength can have the following values: 7 If *ValuePtr is a pointer to a character string, then BufferLength 7 is the number of SQLCHAR elements 7 (or SQLWCHAR elements for the Unicode variant of this function) needed to 7 store the string, or SQL_NTS. 
    If *ValuePtr is a pointer to a binary buffer, then the application places the result of the SQL_LEN_BINARY_ATTR(length) macro in BufferLength. This places a negative value in BufferLength. 
    If *ValuePtr is a pointer to a value other than a character string or binary string, then BufferLength should have the value SQL_IS_POINTER. 
    If *ValuePtr is contains a fixed-length data type, then BufferLength is either SQL_IS_INTEGER or SQL_IS_UINTEGER, as appropriate. 
    7 If the value returned in ValuePtr is a Unicode string, the 7 BufferLength argument must be an even number. 
     
    SQLSMALLINT *  StringLengthPtr  output  A pointer to a buffer in which to return the total number of bytes (excluding the null termination character) available to return in *ValuePtr. If this is a null pointer, no length is returned. If the attribute value is a character string, and the number of bytes available to return is greater than or equal to BufferLength, the data in *ValuePtr is truncated to BufferLength minus the length of a null termination character and is null-terminated by the DB2 CLI.  Usage 
    A call to SQLGetStmtAttr() returns in *ValuePtr the value of the statement attribute specified in Attribute. That value can either be a 32-bit value or a null-terminated character string. If the value is a null-terminated string, the application specifies the maximum length of that string in the BufferLength argument, and DB2 CLI returns the length of that string in the *StringLengthPtr buffer. If the value is a 32-bit value, the BufferLength and StringLengthPtr arguments are not used. The following statement attributes are read-only, so can be retrieved by SQLGetStmtAttr(), but not set by SQLSetStmtAttr(). Refer to the list of statement attributes for all statement attributes that can be set and retrieved. SQL_ATTR_IMP_PARAM_DESC 
    SQL_ATTR_IMP_ROW_DESC 
    SQL_ATTR_ROW_NUMBER 
    Return codes 
    SQL_SUCCESS 
    SQL_SUCCESS_WITH_INFO 
    SQL_ERROR 
    SQL_INVALID_HANDLE 
      

  10.   

    m_retcode=::SQLSetStmtAttr(m_hstmt,SQL_ATTR_CURSOR_TYPE,(SQLPOINTER)SQL_CURSOR_STATIC,0);
    m_retcode=::SQLGetStmtOption(m_hstmt,SQL_ROW_NUMBER,(PTR)&dwRowNumber);
    m_retcode=::SQLGetStmtAttr(m_hstmt,SQL_ATTR_ROW_NUMBER,&dwRowNumber,SQL_IS_UINTEGER,NULL);1.设置属性函数SQLSetStmtAttr返回值为-1
    2.函数SQLGetStmtOption返回值0,dwRowNumber为0
    3.函数SQLGetStmtAttr返回值0,dwRowNumber为0,
      

  11.   

    重新修改了一下,SQLSetStmtAttr设置成功了,但是dwRowNumber为0