Accessing SQL Server 2000 with C , ADO Introduction is the new interface developed by Microsoft Database Application, which is a high-level database access technology built on OLE DB, not only easy to use, and does not indiferous Nice choices for fast development of C using databases. 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 in the SQL2000 Enterprise Management, establishes a database Student, and creates a table stu_info field and the value as follows: Snum sname Sage ssex smajor 200113801 本拉 登 23 Male Computer Science 200104205 Zhang Qiaoqiao 25 female tourism management 200113802 Jacky Cheung 26 male Computer Science III, the list of access procedures is as follows: (Win2000 VC6.0) / ********************************* **************************************** Use ADO to access MS SQL2000 requirements: [1] Output STU_INFO table A record [2] Add a new record [3] Delete the name "Ben Laden" record * / #import "c: / program files / common files / system / ado / msado15.dll" / no_namespace rename ("eof" , "Endoffile" # d
Open (bstrSQL, m_pConnection.GetInterfacePtr (), adOpenDynamic, adLockOptimistic, adCmdText); _variant_t vsnum, vsname, vsage, vssex, vsmajor; // correspond library snum, sname, sage, ssex, smajor cout << "Student ID Name Age surname professional "; cout <<" / n -------------------------------------- ------------------------ / N "; While (! m_precordset-> endoffile) {vsnum = m_precordset-> getCollect (_variant_t ((long) 0)); // This can be VsName = m_precordset-> getCollect ("SNAME"); vssex = m_precordset-> getCollect ("sage"); vssex = m_precordset-> getCollect ("ssex"); vssex = m_precordset-> getCollect ("ssex" ); Vsmajor = m_precordset-> getCollect ("smajor"); if (vsnum.vt! = Vt_null && vsname.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_prec ORDSET-> MoveNext (); /// Move to Next Record} Cout << "/ N ---------------------------- ---------------------------------- / N "; cout <<" / n Please enter you want Added Student Information / N "; COUT <<": "; cin >> student.snum; cout <<" / n Name: "; cin >> student.sname; cout <<" / N age: " Cin>