Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading access file with visual c++ MFC

Status
Not open for further replies.

merlinv

Programmer
Jun 11, 2001
32
0
0
US
I have a access file that I would like to read in a c++ application. I would like to pass a file name and receive data back from the database.

Suggestions?

Thanks in advance.

Merlin Vilhauer
 
Below is the code I am attempting to use. It works fine on
the development machine - but once I export to another machine - I get an error saying this program has ended abnormally and you should contact the vendor.
I am thinking its because the "Provider=Microsoft.Jet.OLEBD.4.0" is not on the machine I am attempting to use this program. Is there a solution for this ?

Thanks.

Merlin Vilhauer
=================== code =========
void ExecuteX()
{
// SELECT SQL

_bstr_t strSQL("SELECT * FROM ReceivedData");
//CONNECTION_STRING


_bstr_t strCnn("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\tmp\\090824M.BWS;");


// Define ADO object pointers. Initialize pointers on define.
// These are in the ADODB:: namespace.
_ConnectionPtr pConnection = NULL;
_CommandPtr pCmdChange = NULL;
_RecordsetPtr pRstTitles = NULL;

try {
// Open connection.
TESTHR(pConnection.CreateInstance(__uuidof(Connection)));
pConnection->Open (strCnn, "", "", adConnectUnspecified);

// Create command object.
TESTHR(pCmdChange.CreateInstance(__uuidof(Command)));
pCmdChange->ActiveConnection = pConnection;

// Open titles table, casting Connection pointer to an
// IDispatch type so converted to correct type of variant.
TESTHR(pRstTitles.CreateInstance(__uuidof(Recordset)));


pRstTitles->Open (strSQL, _variant_t((IDispatch *) pConnection, true),
adOpenStatic, adLockOptimistic, adCmdText);

// Print report of original data.

// Call function to print loop recordset contents.

PrintOutput(pRstTitles);

}
catch (_com_error &e) {
PrintProviderError(pConnection);
PrintComError(e);
}

// Clean up objects before exit.
if (pRstTitles)
if (pRstTitles->State == adStateOpen)
pRstTitles->Close();
if (pConnection)
if (pConnection->State == adStateOpen)
pConnection->Close();
}

=============== code ======================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top