The method and usage of connecting Dao to the database.

Source: Internet
Author: User
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 ();
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.