I. ADO Introduction ADO (ActiveX Data Object) is a new interface developed by Microsoft Database Application. It is a high-level database access technology built on OLE DB, not only easy to use, and it is not easy to use. It is not lost to C uses databases to quickly develop Nice choice. If the theory doesn't have to spend this, there are many online, but the light is theory, nor enough, the ADO access data is very flexible, it is easy to confuse. Most of the online examples are MFC, the database is also Access Many, here I wrote a C language to access the MS SQL2000 instance, I hope to make a comparison of the rookie of my rookie. Second, the establishment of the library first creates a database Student in the SQL2000 Enterprise Management, and creates a table stu_info field and the value as follows:
Snum snamesagessexsmajor 200113801 本拉 登 登 23 Male Computer Science 200104205 Zhang Qiaoqiao 25 Women's Tourism Management 200113802 Jacky Cheung 26 Male Computer Science Third, the list of access procedures is as follows: (Win2000 VC6.0)
/ ************************************************** ***************** Use ADO to access MS SQL2000 requirements: [1] Output STU_INFO table, each record [2] Add a new record [3] Delete name " Ben Laden "record * / #import" c: / program files / compon files / system / ado / msado15.dll "/ no_namespace rename (" eof "," endoffile ") # include
/ N ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------- / N "; While (! m_precordset-> endoffile) {vsnum = m_precordset-> getCollect (_variant_t (long) 0)); // This gives a field Number and field name can be vsName = m_precordset-> getCollect ("sname"); vsage = m_precordset-> getCollect ("Sage"); vssex = m_precordset-> getCollect ("ssex"); vsmajor = m_precordset-> getCollect (" Smajor "); if (vsnum.vt! = vt_null&& vsname.vt! = vt_null && vsage.vt! = vt_null && vssex.vt! = vt_null && vsmajor.vt! = vt_null) {cout.setf (ios :: Left) COUT << SETW (14) << (_ BSTR_T) vSnum; cout << setw (14) << (char *) (_ bstr_t) vsname; cout << setw (8) << vsage.lval; COUT << SETW (8) << (char *) (_ bstr_t) vssex; cout << setw (20) << (char *) (_ bstr_t) vsmajor; cout.unsetf (ios :: left); cout << Endl } M_precordset-> Movenext (); /// Move to the next record} cout << "/ n -------------------------- ------------------------------------ / n "; cout <<" / n Please enter Student information / n "you want to add; cout <<": "; cin >> student.snum; cout <<" / n Name: "; cin >> Tudent.sname; cout << "/ n age:"; cin >> student.sage; cout << "/ n):"; cin >> student.ssex; cout << "/ n professional:"; cin >> student.smajor; m_precordset-> movefirst (); // Move to the first record m_precordset-> addnew ();