CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2005
    Location
    Chennai,India
    Posts
    136

    Lightbulb database handling using API in VC++

    Hi ,,
    Cud Some one tell me how can i handle database in Visual C++ by means of API Functions..

    Thanx in Advance...

  2. #2
    Join Date
    Dec 2002
    Location
    Germany
    Posts
    162

    Re: database handling using API in VC++

    You could use ODBC drivers.
    See this simple code sample:

    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
    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...

  3. #3
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: database handling using API in VC++

    For MySQL you can also use the library which you can download from the developer zone of http://www.mysql.org
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  4. #4
    Join Date
    Aug 1999
    Posts
    586

    Re: database handling using API in VC++

    Quote Originally Posted by C.Schlue
    You could use ODBC drivers.
    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.

  5. #5

    Re: database handling using API in VC++

    Quote Originally Posted by Revolution
    Hi ,,
    Cud Some one tell me how can i handle database in Visual C++ by means of API Functions..

    Thanx in Advance...
    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.

    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
    --

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured