MFC & CResordset Open() fails: Driving me nuts! - Programmer

This is a discussion on MFC & CResordset Open() fails: Driving me nuts! - Programmer ; Here's my complete code, which according to everything I've seen should work! CDatabase db; bool ok = db.Open( szDSN ); // szDSN contains a valid ODBC name, and this returns true CRecordset rs( &db ); rs.Open( AFX_DB_USE_DEFAULT_TYPE, _T("Select * from ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: MFC & CResordset Open() fails: Driving me nuts!

  1. MFC & CResordset Open() fails: Driving me nuts!

    Here's my complete code, which according to everything I've seen
    should work!

    CDatabase db;
    bool ok = db.Open( szDSN ); // szDSN contains a valid ODBC name, and
    this returns true

    CRecordset rs( &db );

    rs.Open( AFX_DB_USE_DEFAULT_TYPE, _T("Select * from myTable") );

    ok is true, and rs.Open throws an exception because no rows are
    returned. (There's a MoveNext() that fails in Open()). The select
    statement returns a few rows when ran from SQL Analyzer.

    If the reason is that I do not bind parameters, I do not want to. I am
    trying to build a generic way to have a SQL statement fill a
    CRecordset, in which I will get the column names after it's filled.

    Either:

    1- There's something wrong with my code above, or

    2- I'm going at this the wrong way. Could you please recommend a
    different tool/class to do this? My bounds are VC++ 6 and MFC, MS SQL
    2005. I want to make no assumption on the returned fields before
    opening the dataset.

    Thanks!

  2. Re: MFC & CResordset Open() fails: Driving me nuts!

    I'm not an expert on this, but here's a few possible pointers:

    1. You may need to derive a class from CRecordset to make this work.

    2. I built a class to extract information in this sort of way - it may
    give you some ideas (http://www.Codeproject.com/KB/database/
    CountSet.aspx).

    3. Is the table name correct? Sometimes you need to add in the owner,
    e.g. dbo.myTable.

    Hope that helps

    Paul.

+ Reply to Thread