My program can be compiled, it is. The CPP file,
# include "stdafx. Hthis is the two functions, establish exe error if remove the list_all function can display similar to the , if you don't take out, , and click on the button, after the exe interface directly disappeared, I feel is the issue of database link
"# include "dormitory management system. H"
# include "MainHostel. H"
# include "MainHostelSet1. H"
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif
/////////////////////////////////////////////////////////////////////////////
//CMainHostel dialog
CMainHostel: : CMainHostel (pParent/*=NULL CWnd * */)
: CDialog (CMainHostel: : IDD, pParent)
{
//{{AFX_DATA_INIT (CMainHostel)
M_Dormitory_dno=_T (" ");
M_louno=_T (" ");
M_rnum=0;
M_wrum=0;
M_dphone=_T (" ");
//}} AFX_DATA_INIT
}
Void CMainHostel: : DoDataExchange (CDataExchange * symbol)
{
CDialog: : DoDataExchange (symbol);
//{{AFX_DATA_MAP (CMainHostel)
DDX_Control (symbol, IDC_LIST_HOSTEL m_HostelList);
DDX_Text (symbol, IDC_EDIT1 m_Dormitory_dno);
DDX_Text (IDC_EDIT2 symbol, m_louno);
DDX_Text (IDC_EDIT3 symbol, m_rnum);
DDX_Text (symbol, IDC_EDIT4 m_wrum);
DDX_Text (symbol, IDC_EDIT5 m_dphone);
//}} AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP (CMainHostel CDialog)
//{{AFX_MSG_MAP (CMainHostel)
ON_BN_CLICKED (IDC_BUTTON_ADDHOSTEL OnButtonAddhostel)
ON_BN_CLICKED (IDC_BUTTON_DELHOSTEL OnButtonDelhostel)
ON_BN_CLICKED (IDC_BUTTON_EDITHOSTEL OnButtonEdithostel)
ON_NOTIFY (NM_CLICK IDC_LIST_HOSTEL, OnClickListHostel)
//}} AFX_MSG_MAP
END_MESSAGE_MAP ()
/////////////////////////////////////////////////////////////////////////////
//CMainHostel message handlers
BOOL CMainHostel: : OnInitDialog ()
{
CDialog: : OnInitDialog ();
M_database. Open (_T (" Liao Libing "));
M_HostelList. SetExtendedStyle (LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP);//the entire line selection, grid lines
M_HostelList. InsertColumn (0, _T (" dormitory "), LVCFMT_LEFT, 100);//insert 2 column name
M_HostelList. InsertColumn (1, _T (" building date "), LVCFMT_LEFT, 100);//insert 3 column name
M_HostelList. InsertColumn (2, _T (" should be the number "), LVCFMT_LEFT, 100);//insert 4 column name
M_HostelList. InsertColumn (3, _T (" real live number "), LVCFMT_LEFT, 100);//insert the fifth column name
M_HostelList. InsertColumn (4, _T (" dormitory telephone "), LVCFMT_LEFT, 100);
Cstrings STR.
STR. The Format (" select * from Dormitory order by dno ");
List_All (STR);
Return TRUE;
}
BOOL CMainHostel: : List_All (cstrings strSQL)
{CDialog: : OnInitDialog ();
M_HostelList. DeleteAllItems ();
CMainHostelSet1 m_Dormitory;
Try {
If (m_Dormitory IsOpen ())
M_Dormitory. Close ();
if (! M_Dormitory. Open (CRecordset: : the snapshot, strSQL)) {
MessageBox (" open the database fail ", "connect to the database", MB_OK);
return false;
}
}
The catch (CDBException * e) {
E - & gt; ReportError ();
}
Int nIndex=0;
M_Dormitory. MoveFirst ();
while (! M_Dormitory. IsEOF ()) {
LV_ITEM litem;
Litem. Mask=LVIF_TEXT;
Litem. IItem=nIndex;
Litem. ISubItem=0;
M_HostelList. InsertItem (& amp; Litem);
M_HostelList. SetItemText (nIndex. Zero, m_Dormitory m_Dormitory_dno);
M_HostelList. SetItemText (nIndex, 1, m_Dormitory m_louno);
Cstrings wrum="";
Cstrings rnum="";
Wrum. The Format (_T (" % 3 d "), m_Dormitory. M_wrum);
Rnum. The Format (_T (" % 3 d "), m_Dormitory. M_rnum);
M_HostelList. SetItemText (nIndex. 2, rnum);
M_HostelList. SetItemText (nIndex, 3, wrum);
M_HostelList. SetItemText (nIndex, 4, m_Dormitory m_dphone);
M_Dormitory. MoveNext ();
NIndex++;
}
M_Dormitory. Close ();
return true;
}
If is press F5 to run, can appear the following status according to the determined after
Database connection as follows [code=text# include "stdafx. H
"# include "dormitory management system. H"
# include "MainHostelSet1. H"
# ifdef _DEBUG
# define new DEBUG_NEW
# undef THIS_FILE
The static char THIS_FILE []=__FILE__;
# endif
/////////////////////////////////////////////////////////////////////////////
//CMainHostelSet1
IMPLEMENT_DYNAMIC (CMainHostelSet1 CRecordset)
CMainHostelSet1: : CMainHostelSet1 (CDatabase * PDB)
: CRecordset (PDB)
{
//{{AFX_FIELD_INIT (CMainHostelSet1)
M_dphone=_T (" ");
M_louno=_T (" ");
M_rnum=0;
M_wrum=0;
M_Dormitory_dno=_T (" ");
M_nFields=5;
//}} AFX_FIELD_INIT
M_nDefaultType=the snapshot;
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull