Hi ,,
Cud Some one tell me how can i handle database in Visual C++ by means of API Functions..
Thanx in Advance...
Printable View
Hi ,,
Cud Some one tell me how can i handle database in Visual C++ by means of API Functions..
Thanx in Advance...
You could use ODBC drivers.
See this simple code sample:
You will need the propper ODBC Driver for your Database System. MSSQL and MSAccess Drivers are shipped with Windows as far as I know. MySQL Drivers are available for download...Code:CDatabase db ;
BOOL bSuccess;
TRY
{
CString strDriver = "SQL Server";
CString strConnect;
bSuccess = db.OpenEx( _T("DRIVER=MySQL ODBC 3.51 Driver;DATABASE=test") );
if( bSuccess)
{
//db.ExecuteSQL( _T("INSERT INTO TABLE1 VALUES(1, \"test string\")") );
CRecordset query( &db );
query.Open( CRecordset::snapshot,
_T("SELECT * FROM TABLE1") );
while(query.IsEOF() == 0)
{
CDBVariant value;
query.GetFieldValue(_T("test"), value);
query.MoveNext();
}
bSuccess = FALSE;
}
}CATCH_ALL ( ex)
{
TCHAR pszmsg[256];
ex->GetErrorMessage(pszmsg, 256);
}
END_CATCH_ALL
For MySQL you can also use the library which you can download from the developer zone of http://www.mysql.org
ODBC is antiquated. Depending on what he's doing, new development should usually rely on ADO which is just a high-level (COM) wrapper around OLE/DB (also COM). He should check out the #import statement in VC++ using the OLE/DB provider for his partiular DB. OTOH, ADO.NET should be explored if he's working in that environment instead (.NET). Both subjects are widely documented online.Quote:
Originally Posted by C.Schlue
From another viewpoint, how you handle databases in Visual C++ depend on the API functions provided by databases such as MySQL, Firebird Server, PostgreSQL, and others.Quote:
Originally Posted by Revolution
The API functions, usually C API functions, provided by these databases allow direct access without having to go through ODBC.
There are also C++ libraries that wrap the C API functions. For example, there is MySQL++ for MySQL and IBPP, a C++ client interface for
Firebird Server & InterBase.
Best Regards,
Yeoh
--