VB icon

Access MDB

Submitted on: 1/1/2015 10:51:00 PM
By: Mokarrabin A Rahman (from psc cd)  
Level: Beginner
User Rating: By 12 Users
Compatibility: C, C++ (general), Microsoft Visual C++
Views: 5617
     To open MS Access or Ms SQL server database using C/C++ or VC++
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
// Name: Access MDB
// Description:To open MS Access or Ms SQL server database using C/C++ or VC++
// By: Mokarrabin A Rahman (from psc cd)
// Returns:Shows some recordsets
// Assumes:Change the name of the database to any database and place it in the same directory as the .exe. You shoul also change the SQL to your particular database. You may change the connect string to connect to MS SQL Server.
// Side Effects:Great

#import "c:\Program Files\Common Files\System\ADO\msado15.dll" no_namespace rename("EOF", "EndOfFile")
// This code comes from : www.geocities.com/mokarrabin
#include <stdio.h>
#include <iostream.h>
void main(void)
_RecordsetPtr pRst("ADODB.Recordset");
 // Connection String
_bstr_t strCnn("DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;DBQ=GBOOK.mdb");
	 // Open table
	pRst->Open("SELECT * FROM ProductService where ProductService like '%samir%';", strCnn, adOpenStatic, adLockReadOnly, adCmdText);
	 while (!pRst->EndOfFile) {
		 cout<<(char*) ((_bstr_t) pRst->GetFields()->GetItem("ProductService")->GetValue())<<endl;
catch (_com_error &e)
 cout<<(char*) e.Description();

Other 2 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.