Can't update row data with SQLSetPos 
Author Message
 Can't update row data with SQLSetPos

Hi!

I have some code to fetch one row of data and printing the result. This
works fine.
But when I try to update the row with SQLSetPos(..., SQL_UPDATE, ...), the
call fails and give me an:
HY109   [Microsoft][ODBC SQL Server Driver]Invalid cursor position
error message.

I'm very new to this and I can't figure out what I'm doing wrong.

All help is apreciated!

Sincerley Torkel

int main(int argc, char* argv[])
{
 SQLCHAR url[256+1], my_str[100+1], keys[256+1];
 SQLINTEGER cid, id, status, date, my_int;
 SQLINTEGER l_cid, l_id, l_url, l_status, l_date, l_my_int, l_my_str,
l_keys;
 int row=0;

    cout << "Conecting..." ;
    if (!openDB("cwc")) {
  cout << "error" << endl;
  exit(1);
    }
    cout << "ok" << endl;

 /* Allocate statement handle */
    SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);

 /* Set attributes */
 SQLSetStmtAttr(hstmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_DYNAMIC,
SQL_IS_INTEGER);
 SQLSetStmtAttr(hstmt, SQL_ATTR_CONCURRENCY, (SQLPOINTER)SQL_CONCUR_ROWVER,
SQL_IS_INTEGER);

 /* Executing SQL command */
    rc = SQLExecDirect(hstmt, (unsigned char *)"sp_cwc 'getall'", SQL_NTS);

 if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
  cout << "SQLExecDirect() failed!" << endl; sql_error(hstmt);
  exit(1);
 }

 /* Bind columns */
 SQLBindCol(hstmt, 1, SQL_C_ULONG, &cid, 0, &l_cid);
 SQLBindCol(hstmt, 2, SQL_C_ULONG, &id, 0, &l_id);
 SQLBindCol(hstmt, 3, SQL_C_CHAR, url, sizeof(url), &l_url);
 SQLBindCol(hstmt, 4, SQL_C_ULONG, &status, 0, &l_status);
 SQLBindCol(hstmt, 5, SQL_C_DATE, &date, 0, &l_date);
 SQLBindCol(hstmt, 6, SQL_C_CHAR, my_str, sizeof(my_str), &l_my_str);
 SQLBindCol(hstmt, 7, SQL_C_ULONG, &my_int, 0, &l_my_int);
 SQLBindCol(hstmt, 8, SQL_C_CHAR, keys, sizeof(keys), &l_keys);

 /* Fetch and print each row of data.  On */
 /* an error, display a message and exit. */
 while (++row) {
  //rc = SQLFetch(hstmt);
  rc = SQLFetchScroll(hstmt, SQL_FETCH_NEXT, 0);
  if (rc == SQL_NO_DATA) { cout << "end of table.\n"; break; }

  if (rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO){
   cout << cid << "\t" << id << "\t" << url << "\t" << status << "\t";
   if (l_keys != -1) { cout << keys; }
   cout << endl;
  } else { cout << "Fetch error!" << endl; sql_error(hstmt); }

  /* Update data */
  status = 0;
  rc = SQLSetPos(hstmt, row, SQL_UPDATE, SQL_LOCK_EXCLUSIVE);
  if ( !(rc == SQL_SUCCESS || rc == SQL_SUCCESS_WITH_INFO) )
   sql_error(hstmt);
 }

 if (hstmt) SQLFreeHandle(SQL_HANDLE_STMT, hstmt);

    closeDB();
    return 0;

Quote:
}



Thu, 08 May 2003 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Changing the row status array used by SQLSetPos

2. Changing the row status array used by SQLSetPos

3. Updating bulk rows of data

4. single row updates effect multiple rows....

5. Oracle ODBC-Driver doesn't update data

6. ? TabCtrl data won't update

7. Help: "Multiple rows were updated error' or is problem MFC's Update()

8. SQL/VC++ Updates: Can't update recordset

9. Q: Error message "Multiple rows updated"???

10. No rows were updated pb

11. Problem locking a row for updating

12. Insert, Update, Delete of rows using OLE DB ATL Consumer Templates

 

 
Powered by phpBB® Forum Software