Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. CRecordset field access errors

CRecordset field access errors

Scheduled Pinned Locked Moved Database
helpdatabasesql-servercomperformance
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dels
    wrote on last edited by
    #1

    Hi, I'm having big trouble accessing recorset elements. I'm using ODBC(MSSQL) with CDatabase and CRecordset objects, I can perform SQL executes, and even seem to open recordsets without bother but come into trouble when I try to access a recordset field. I have CDatabase* called pDB. I have used recordsets previously but only used to check the number of rows returned (and thus not attempted to read any fields). As far as I can tell there shouldn't be a problem here (I've copied most of this section straight from MSDN). The SQL statement returns a 1 row of 1 field recordset and the datatype of that element is varchar. Hi, I've written the following code char strSQL[2048]; try { sprintf(strSQL,"SELECT DataValue FROM dbo.SSEData WHERE (DataName = N'LOGON')"); printf("%s\n\n\n", strSQL); CRecordset rs(pDB); printf("Just setup Filter\n"); if ( rs.Open( CRecordset::snapshot, strSQL) ) printf("Just opened recordset\n"); else printf("Failed to open recordset\n"); if (rs.GetRecordCount() == (long)0){ printf("No records found"); } else { if ( rs.IsEOF() ) printf("The recordset was EOF"); if ( rs.IsBOF() ) printf("The recordset was BOF"); printf("Field Count : %d \n", rs.GetODBCFieldCount() ); rs.AssertValid(); printf("Recordset was greater than nothing\n"); CString CStartupMessage; CDBVariant CVariantField; printf("In between the first and last string\n"); // rs.GetFieldValue( (short)0, CVariantField ); rs.GetFieldValue( short(0), CStartupMessage); printf("Got the field value\n"); } rs.Close(); } catch(CDBException *e){ printf("Caught a DB exception\n"); e->Delete(); } catch(CMemoryException *m){ printf("Caught a memory error\n"); TCHAR ErrorMessage[256]; m->GetErrorMessage( ErrorMessage, 255); printf("Finished capturing error %s\n", ErrorMessage); } The Output from this code is: .... Just setup Filter Just opened recordset Field Count : 1 Recordset was greater than nothing In between the first and last string Caught a memory error Can anybody help me ???? Thanks, Damian Del Campo (damian_jose@yahoo.com)

    P 1 Reply Last reply
    0
    • D Dels

      Hi, I'm having big trouble accessing recorset elements. I'm using ODBC(MSSQL) with CDatabase and CRecordset objects, I can perform SQL executes, and even seem to open recordsets without bother but come into trouble when I try to access a recordset field. I have CDatabase* called pDB. I have used recordsets previously but only used to check the number of rows returned (and thus not attempted to read any fields). As far as I can tell there shouldn't be a problem here (I've copied most of this section straight from MSDN). The SQL statement returns a 1 row of 1 field recordset and the datatype of that element is varchar. Hi, I've written the following code char strSQL[2048]; try { sprintf(strSQL,"SELECT DataValue FROM dbo.SSEData WHERE (DataName = N'LOGON')"); printf("%s\n\n\n", strSQL); CRecordset rs(pDB); printf("Just setup Filter\n"); if ( rs.Open( CRecordset::snapshot, strSQL) ) printf("Just opened recordset\n"); else printf("Failed to open recordset\n"); if (rs.GetRecordCount() == (long)0){ printf("No records found"); } else { if ( rs.IsEOF() ) printf("The recordset was EOF"); if ( rs.IsBOF() ) printf("The recordset was BOF"); printf("Field Count : %d \n", rs.GetODBCFieldCount() ); rs.AssertValid(); printf("Recordset was greater than nothing\n"); CString CStartupMessage; CDBVariant CVariantField; printf("In between the first and last string\n"); // rs.GetFieldValue( (short)0, CVariantField ); rs.GetFieldValue( short(0), CStartupMessage); printf("Got the field value\n"); } rs.Close(); } catch(CDBException *e){ printf("Caught a DB exception\n"); e->Delete(); } catch(CMemoryException *m){ printf("Caught a memory error\n"); TCHAR ErrorMessage[256]; m->GetErrorMessage( ErrorMessage, 255); printf("Finished capturing error %s\n", ErrorMessage); } The Output from this code is: .... Just setup Filter Just opened recordset Field Count : 1 Recordset was greater than nothing In between the first and last string Caught a memory error Can anybody help me ???? Thanks, Damian Del Campo (damian_jose@yahoo.com)

      P Offline
      P Offline
      Prem Kumar
      wrote on last edited by
      #2

      Just try rs.MoveFirst()

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups