Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to connect Access database with c language? Standard c language
How to connect Access database with c language? Standard c language
1 and C/C++ interact with databases, such as mssql/ mysql/oracle. Generally, there are mature third-party libraries, which only encapsulate the communication mode and communication protocol with the database. Searching API documents related to the database will make it clear that any file is binary data, and the key is the organization of data storage, such as gif/doc/jpg/wav.

2. For example, connect to SQL:

//? Open the database

strDBClass。 Format(_T("Provider=Microsoft。 Jet. OLEDB.4.0 data? Source =% s;; Jeter? OLEDB: database? Password =%s "), m _ strUnEntryptMdbFilePath,m _ strmdb password);

//? Create a connection

HRESULT? hr? =? M _ connection. create instance(_ uuidof(Connection));

_ConnectionPtr? M _ connection-> Open(m_strDBClass,_T(" ",_T(" ",adconnect unspecified);

//? Declare form pointer

_RecordsetPtr? pBandRecordset

pBandRecordset。 create instance(_ _ uuidof(Recordset));

//? execute statement

CString? strSQL(L"SELECT? *? From where? [Band] ";

M _ connection-> Execute((LPCTSTR)strSQL,NULL,0);

//? Select a project? For example, BandInfo

int? iBandInfo? =? Wcscmp (column, l "bandinfo");

And (! recordsetPtr-& gt; adoEOF)

{

var? =? recordsetPtr-& gt; get collect(colum);

if(var.vt? ! =? VT_NULL)

strName? =? (LPCSTR)_ bstr _ t(var);

recordsetPtr-& gt; MoveNext();

}