CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Urgent:Connecting a dialog box with a database

    I want to have the display section for database in a dialog box. The name of my application is dlgdb. I have made a forward declaration for dlgdbSet in the dialog class. Also m_pSet is declared as the member of dialog class. But when I am trying to use m_pSet->Open or any other CRecordset function, I am getting Unhandled exception error. Pl. help me in this regard.
    Zulfi.


  2. #2
    Join Date
    Apr 1999
    Posts
    306

    Re: Urgent:Connecting a dialog box with a database

    we must see some of your code otherwise it is not possible to guess what is wrong.


  3. #3
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Urgent:Connecting a dialog box with a database

    The project name is dlgdb. The database fields & their corresponding variables in dlgdbSet are as follows:
    [Email Add] CString m_Email_Add
    [Fine] long m_Fine
    [Mem Name] CString m_Mem_Name
    [Mem No] CString m_Mem_No
    [Mem Type] CString m_Mem_Type

    I have a dialog class CDisplay which I want to use for display of database members. The code is as follows(Display.h):

    class CDlgdbSet;
    class CDisplay : public CDialog {
    ://Class Wizard Generated code; skipped
    :
    :
    //Dialog Data
    //{{AFX_DATA(CDisplay)
    enum {IDD = IDD_DIALOG1;
    CString m_Email;
    long m_Fine;
    CString m_MemID;
    CString m_MemName;
    CString m_MemType;
    //}}AFX_DATA

    CDlgdbSet* m_pSet;//Added by myself
    :
    :
    :
    };

    In the dlgdbView.cpp, I have addedd a function

    void CDlgdbView::OnDispItem()
    {
    CDisplay dlg;
    dlg.DoModal();
    }

    In Display.cpp I have coded which can fill the edit boxes with values from database on start up

    BOOL CDisplay::OnInitDialog() {
    CDialog::OnInitDialog();

    m_pSet->Open(); //Run time error at this //in the code
    m_Email=m_pSet->m_Email_Add;
    :
    :
    :
    UpdateData(FALSE);
    }




  4. #4
    Join Date
    Apr 1999
    Posts
    306

    Re: Urgent:Connecting a dialog box with a database

    As far as I can see, correct the following if it still does not work call me again.

    You have a pointer of type CdbdlgSet. OK, but this pointer points to no valid CdbdlgSet object. So try this:

    in your dialog and a member that is not a pointer, but an object, like:

    public:
    CDbDlgSet m_set;

    then in the InitDialog() call like this:

    if (! m_set.IsOpen()) m_set.Open();

    If this is not the problem I will think over your code again.

    Regards,
    ric


  5. #5
    Guest

    Re: Urgent:Connecting a dialog box with a database

    CDialog::OnInitDialog()
    {
    m_pSet = new CDlgdbSet(ptr to your database name );
    m_pSet->Open(); //Run time error at this //in the code
    m_Email=m_pSet->m_Email_Add;
    :
    :
    :
    UpdateData(FALSE);
    }


  6. #6
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Urgent:Connecting a dialog box with a database

    Hi, I tried your option
    public:
    CDlgdbSet m_Set;
    I am getting following error
    "m_Set uses undefined class CDlgdbSet" but if I put the pointer back like this
    CDlgdbSet* m_Set;
    The error goes off.
    Waiting for your reply


  7. #7
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Urgent:Connecting a dialog box with a database

    How I can obtain a ptr to my database name? I applied the following but not working
    m_pSet = new CDlgdbSet("ODBC;DSN=Library2");

    Zulfi.


  8. #8
    Join Date
    Apr 1999
    Posts
    306

    Re: Urgent:Connecting a dialog box with a database

    Just include the dbdlgset header file in your dialog header file, like:

    #include "dbdlgset.h"


  9. #9
    Join Date
    Apr 1999
    Location
    Pakistan
    Posts
    207

    Re: Urgent:Connecting a dialog box with a database

    Thanks ric, its running. Thanks again for your interest.
    Zulfi.


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