MSSQL ODBC getfieldvalue throwing exception

Posted on 2004-11-14
Last Modified: 2013-11-20
When I access my Access database using ODBC and getfieldvalue in forward field index order or backward index order I have no problems.
When I try to access the same database converted to MSSQL using a variety of converters and simply point at the new ODBC connection, DBCORE.CPP throws an error "GetFieldValue operation failed on field" if I try to fietch a field using an index less than the last field fetched.

My code (simplified) is :

    CString cstrg;

    rs.Open(CRecordset::dynaset,"SELECT * from DATAB");
    rs->GetFieldValue(5,cstrg);    \\Succeeds
    rs->GetFieldValue(7,cstrg);    \\Succeeds
    rs->GetFieldValue(4,cstrg);    \\ Fails

Is this a limitation of the MSSQL ODBC driver ?

To fetch in any other order is a real problems.

Any ideas ??


Question by:PSernz
    LVL 55

    Expert Comment

    by:Jaime Olivares
    First step I suggest you is to compare field type of Access and MSSQL table.

    Author Comment


    Field types are not a problem.  These are text fields that can be viewed and changed in MS SQL using any of the query tools without a problem.  I can access all the fields ok if I access them in index order.  If I try to access a field with an index earlier than the last index I get the error.

    Very strange.

    LVL 43

    Expert Comment

    Does it still fail if you try by name instead of by ordinal value?
    LVL 43

    Expert Comment

    Is the field null?  (That should not be a problem with string values but...)

    Author Comment

    Have not tried name fetch.  Can't imagine it will make a difference.
    The fields carry text.  All of the fields fail if you fetch a field with index less than the last field fetched.

    Author Comment

    I've found the problem.
    SQLGetData (used by getfieldvalue) can not fetch columns in reverse order. Documented....
    Sounds incredible but true.
    This means that ODBC routines used toward Access will not work for MS SQL.
    Thanks Microsoft...

    Accepted Solution

    PAQed with points refunded (500)

    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now