CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Error in Recordset

    Following peice of code is giving error as in attachment, please help


    #include "stdafx.h"
    #include <iostream.h>
    #include <afxdb.h>

    int main(int argc, char* argv[])
    {
    CDatabase myDatabase;
    CString strConnect;

    strConnect = _T("DSN=DB110_32;User Id=#ISL1Q1;PASSWORD=SYSLOG01;SRVR=DB110;DB=ccyud001;UID=#ISL1Q1;");
    try
    {
    myDatabase.OpenEx(strConnect);
    }

    catch(...)
    {
    cout << "Error in opening Database" << endl;
    return 0;
    }
    cout << "connection is successful" << endl;

    try
    {
    CRecordset rs(&myDatabase);

    rs.m_strSort = "proj_num, contact_name";

    rs.Open(CRecordset:ynaset,_T("ccy003_proj"));
    rs.Close();
    }

    catch(...)
    {
    cout << "again some error in rs" << endl;
    return 0;
    }

    myDatabase.Close();
    return 0;
    }
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    You have to derive your recordset from the CRecordset class and bind all columns you need to the variables prior to call the recordset’s Open member function. Use the ClassWizard to create a CYourRecordset class derived from the CRecordset and bind columns. The columns will be bound to the variables in the CYourRecordset:: DoFieldExchange function.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Error in Recordset

    Also catch a CDBException* not ... and get its error message.

    Also, click retry when you get an assertion to see exactly what code caused the assertion.

  4. #4
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    Thanks for your help. I have done the following changes.
    I have dereived a class from Crecordset and done DoFieldExchange as below
    ====
    class CMyProjectClass : public CRecordset
    {
    public:
    CMyProjectClass();
    virtual ~CMyProjectClass();
    virtual void DoFieldExchange( CFieldExchange* pFX );

    int m_nProjectNumber;
    CString m_strCustomerName;

    };


    CMyProjectClass::CMyProjectClass()
    {

    }

    CMyProjectClass::~CMyProjectClass()
    {

    }

    void CMyProjectClass:oFieldExchange( CFieldExchange* pFX )
    {
    pFX->SetFieldType(CFieldExchange:utputColumn);
    RFX_Text(pFX, "contact_name", m_strCustomerName);
    RFX_Int(pFX, "proj_num", m_nProjectNumber);
    }

    ====

    In the main file, I have done

    ====
    try
    {
    CRecordset rs(&myDatabase);

    rs.Open(CRecordset:ynaset,_T("select contact_name,proj_num from ccy003_proj"));
    rs.Close();
    }
    ====

    Still, I am getting the same error. Can you help me?

    Sunny

  5. #5
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    First of all sorry for those smiles (I dont know how did they creap in)
    When I tried to debug, I got error in afxwin1.inl at..

    ======
    _AFXWIN_INLINE HINSTANCE AFXAPI AfxGetResourceHandle()
    { ASSERT(afxCurrentResourceHandle != NULL);
    return afxCurrentResourceHandle; }
    ======

    Sunnypriya

  6. #6
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    I have solved the problem, but still unable to reach my final solution.
    (reason snapshot is allowed)

    ==========================

    try
    {
    CMyProjectClass rs(&myDatabase);
    rs.Open(CRecordset::snapshot,_T("Select proj_num, contact_name from dbo.ccy003_project"));
    cout << rs.m_strCustomerName << endl;
    rs.MoveNext();
    cout << rs.m_strCustomerName << endl;
    rs.Close();

    }

    catch (CDBException* myexcept)
    {
    cout << myexcept->m_strError << endl;
    return 0;
    }

    ==========================

    Problem, at the statemet rs.Open ......
    I am forced to give all the details again, (please see the attachement for the steps).
    Once I did, CDBException exception is raised, with reason
    ====================
    No columns were bound prior to calling SQLFetchScroll/SQLExtendedFetch
    ====================

    Thou, I have coded below part.

    void CMyProjectClass:oFieldExchange( CFieldExchange* pFX )
    {
    pFX->SetFieldType(CFieldExchange:utputColumn);
    RFX_Text(pFX, "contact_name", m_strCustomerName);
    RFX_Int(pFX, "proj_num", m_nProjectNumber);
    }


    Now, will this function be called implicitly or I have to call explicitly? How do I have to call? what is the method to bound the columns?


    Hope answer to this will solve my problem.

    Regards
    SUNNYPRIYA
    Attached Files Attached Files

  7. #7
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    This code should help you to find the problem with the exception.
    Code:
    try
    {
    CMyProjectClass rs(&myDatabase);
    rs.Open(CRecordset::snapshot,_T("Select proj_num, contact_name from dbo.ccy003_project"));
    while(!rs.EOF())
    {
        cout << rs.m_strCustomerName << endl;
        rs.MoveNext();
    }
    rs.Close();
    
    }
    catch (CDBException* myexcept)
    {
    cout << myexcept->m_strError << endl;
    return 0;
    }
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  8. #8
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    I am getting the following exception
    ============
    No columns were bound prior to calling SQLFetchScroll/SQLExtendedFetch
    ============

  9. #9
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    Could you post the CMyProjectClass files?
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  10. #10
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    I am posting the file..
    please help..
    Attached Files Attached Files

  11. #11
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    Your recordset files are not complete. Use Class Wizard to generate these files (View->ClassWizard->Add Class->New).
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  12. #12
    Join Date
    May 2002
    Location
    Mumbai
    Posts
    197

    Re: Error in Recordset

    Hi, I have done some R&D and able to solve the problem, I am not getting any error, but values of the variables are the same as they have been set in the constructor.
    I think we are close to answer, please help.
    I am attaching the files again.
    Attached Files Attached Files

  13. #13
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Error in Recordset

    You don't need the select statement in the recordset open. The CRecordset class handles all that for you. I don't know if that's your current problem, but it's definitely a problem.

  14. #14
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    Quote Originally Posted by SunnyPriya
    Hi, I have done some R&D and able to solve the problem, I am not getting any error, but values of the variables are the same as they have been set in the constructor.
    I think we are close to answer, please help.
    I am attaching the files again.
    Use the Class Wizard to generate your recordset files. In your files the macros in *.cpp (AFX_FIELD_INIT, AFX_FIELD_MAP AFX_FIELD) and *.h (AFX_FIELD, AFX_VIRTUAL) are missed. I have attached sample files generated by the Class Wizard.
    Attached Files Attached Files
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

  15. #15
    Join Date
    Jun 2004
    Location
    Chicago, United States
    Posts
    88

    Re: Error in Recordset

    Quote Originally Posted by GCDEF
    You don't need the select statement in the recordset open. The CRecordset class handles all that for you. I don't know if that's your current problem, but it's definitely a problem.
    It's not true. The CRecordset class doesn't do it for you. You have to specify the select statement in the recordset open function.
    Last edited by amarcode; January 4th, 2005 at 09:49 PM.
    A.M.
    My Latest Articles:
    CCustomBitmapButton - An owner-draw button and a frame for the caption bar, in one class.
    CCustomTabCtrl - A clone of the Excel tab sheet control.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured