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