C language ODBC database operations, odbc database

Source: Internet
Author: User

C language ODBC database operations, odbc database

Today, we will introduce how to operate databases in C language. Here we use ODBC. The environment is WIN7 + VC6. The other environments are similar.

The first step is to configure the environment and add data sources. I will not explain it here. There are a lot of related information on the Internet. It should be noted that ODBC in the control panel cannot be directly used here. We need to open the data source odbcad32.exe in C: \ Windows \ syswow64. The added data source is as follows:

Here we use VC to create a single-document view application, add database support, and select a data source. The details are as follows:

Add controls

Bind fields in the database to ClassWizard

Delete data:

// Delete

M_pSet-> Delete ();

If (! M_pSet-> IsEOF ())

M_pSet-> MoveNext (); // delete a record after the cursor, that is, delete the current record.

Else

M_pSet-> MoveLast ();

M_pSet-> Requery ();

Add new item:

M_pSet-> AddNew ();

M_pSet-> SetFieldNull (& m_pSet-> m_ID, FALSE );

GetDlgItemText (IDC_USER, m_pSet-> m_username );

GetDlgItemText (IDC_PASSWORD, m_pSet-> m_password );

M_pSet-> Update ();

M_pSet-> MoveLast ();

M_pSet-> Requery ();

Modify:

M_pSet-> Edit ();

GetDlgItemText (IDC_USER, m_pSet-> m_username );

GetDlgItemText (IDC_PASSWORD, m_pSet-> m_password );

M_pSet-> Update ();

M_pSet-> Requery ();

Record it and keep it for future reference. It is also convenient for others.

Thank you for your support!

You can contact me. Renhanlinbsl@163.com

2016.2.5

2:23

Related Article

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.