CRecordset problems in MFC

  • Hi All, hope you can help me out here, I have been having a REALLY hard time with this.

     

    I am trying to get Data from an MSDE 2000 Database using VC++ 6.0 and MFC.  I have configured the ODBC .DSN file and the Database correctly, as I tested it out with some other application (and with the test button in the ODBC control Panel applet).

     

    In my code, I create a CDatabase object, which opens the database.  To test that it worked, I used the ExecuteSQL command and changed some values in the DB with a SQL call, and it worked fine.  Now the problem is the CRecordset object.  I create a CRecordset object based on the current open DB – works fine.  I run the member “GetODBCFieldCount” to get the field count.  No problemo.  I use the “GetODBCFieldInfo” to find out the name of the first field – still no problem.  

     

    BUT ….

     

    When I make the call to the GetFieldData member, it pukes up and gives me this error:

     

    “Error: GetFieldValue operation failed on field 0.

    Invalid Descriptor Index

    State:S1002,Native:0,Origin:[Microsoft][ODBC SQL Server Driver]”

     

    Now I have the latest version of MDAC on this machine (ver. 2.8) and when I called the “open” command on the CDatabase, I made sure to use the “OpenEx” flavour, so as to not allow the cursor library to load (which I thought was an issue.

     

    Here is a basic code snippets:

     

    if (0!=objDB->OpenEx(_T("DSN=VIVOSONIC;UID=sa;PWD=''")));

                {          

    // Set Up the Field Names

    CString strCmd = "UPDATE Protocol SET Name='Georgiana' ";

    //test the DB connection

    objDB->ExecuteSQL(strCmd);

     

    CRecordset objRecSet(&objDB);

    CRecordset *pRecSet=NULL;

    if(0!=objDB->IsOpen ())

                {

    retVal=objRecSet.Open(AFX_DB_USE_DEFAULT_TYPE, "Protocol");

                }

                pRecSet = &objRecSet;

    iRecordCount = pRecSet->GetRecordCount();

                num_cols = pRecSet->GetODBCFieldCount ();

     

    f (iRecordCount > 0)

    {

                pRecSet->MoveFirst ();

                while(!pRecSet->IsEOF ())

                {       

     

    for (iCntr2=0; iCntr2< pRecSet->GetODBCFieldCount()-3; iCntr2++)

    {

    pRecSet->GetODBCFieldInfo(iCntr2, objFieldInfo);

    if (( objFieldInfo.m_strName == "RecordId") && (iCntr2 < 1))

    {                                                          

    pRecSet->GetFieldValue(objFieldInfo.m_strName, varValue);

     

    And it blows up right here!  Ahhhh! Can anyone give any ideas?

     

    Thanks for your help,

     

    Jt

    Email: temprile@vivosonic.com

  • Hi There,

     I've found your post as I've got the very same problem and I'm dying to find a solution. Have you find a solution to this problem?

     

    Thanks,

    Alex.

  • Hi There,

     I've found your post as I've got the very same problem and I'm dying to find a solution. Have you find a solution to this problem?

     

    Thanks,

    Alex.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply