I spent a lot of time studying the connection and modification of Access Database Using Dao in VC. Today, the key source code is finally solved as follows:
Void cdaotestdlg: onok ()
{
// Todo: add extra validation here try
{
// The first method is passed in vc6.0
Cdaodatabase dB;
Cstring STR;
// Modify the path according to the actual path
STR = "D: \ phone. mdb ";
// Afxgetmodulestate ()-> m_dwversion = 0x0601;
DB. Open (STR );
DB. Execute ("delete * from phones ");
DB. Close ();
// The second method is used. You need to adjust the database file daotest. mdb to the DEBUG directory.
/*
Tchar m_tzfilename [250];
Getmodulefilename (null, m_tzfilename, max_path );
Lstrcpy (m_tzfilename + lstrlen (m_tzfilename)-4, text (". mdb "));
Cdaodatabase dB;
DB. Open (lpctstr) m_tzfilename );
DB. Execute ("delete * from phones ");
DB. Close ();
*/
// The following is the third method.
/* Cdaodatabase dB;
Cdaorecordset recset (& dB );
Cstring sqlcmd = "select * from phones where pole = '000000 '";
DB. Open ("daotest. mdb", false, false );
Recset. Open (afx_dao_use_default_type, sqlcmd, null );
DB. Execute ("delete * from phones ");
DB. Close ();
*/
}
Catch (cdaoexception * PE)
{
Afxmessagebox (PE-> m_perrorinfo-> m_strdescription,
Mb_iconexclamation );
MessageBox ("data error! "," Add data ", mb_iconerror + mb_ OK );
Pe-> Delete ();
}
}