Click to See Complete Forum and Search --> : Urgent:Connecting a dialog box with a database


Zulfi Khan
June 4th, 1999, 05:30 AM
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.

ric
June 4th, 1999, 06:46 AM
we must see some of your code otherwise it is not possible to guess what is wrong.

Zulfi Khan
June 8th, 1999, 03:45 AM
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);
}

ric
June 8th, 1999, 06:08 AM
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

June 8th, 1999, 07:59 AM
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);
}

Zulfi Khan
June 9th, 1999, 12:37 AM
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

Zulfi Khan
June 9th, 1999, 12:59 AM
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.

ric
June 9th, 1999, 03:58 AM
Just include the dbdlgset header file in your dialog header file, like:

#include "dbdlgset.h"

Zulfi Khan
June 9th, 1999, 05:18 AM
Thanks ric, its running. Thanks again for your interest.
Zulfi.