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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO To MS Access Database.

Status
Not open for further replies.

mikecertini

Programmer
Feb 21, 2011
1
US
I am having problems with executing a command object in ADO. Can someone help me with interpreting the below error? Listed below is the complete program:

Here is my error message coming out of the try block:

Connection object created.
Connection has been opened.
Error
Code = 80040e14
Code meaning = I
Source = Microsoft JET Database Engine
Description = Expected query name after EXECUTE.

#include <stdio.h>
#include <string>
using std::string;

int cyc = 0;

#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","EOFile")
using namespace std;

struct StartOLEProcess{
StartOLEProcess( ) {
::CoInitialize(NULL);
}
~StartOLEProcess( ) {
::CoUninitialize( );
}
} _start_StartOLEProcess;

void main(void)
{
// define our variables which will be used as references to the
// Connection and Recordset objects

ADODB::_ConnectionPtr con = NULL;
ADODB::_RecordsetPtr rec = NULL;
ADODB::_CommandPtr com = NULL;
ADODB::_ParameterPtr par = NULL;

// create two strings for use with the creation of a Connection
// and a Recordset object

bstr_t sConString;
bstr_t sSQLString;

// create a variable to hold the result to function calls

HRESULT hr = S_OK;

// long variable needed for Execute method of Connection object

VARIANT *vRecordsAffected = NULL;

// create instance of an ADO Connection object, ADO Command object, ADO Parameter object, ADO Record object

hr = con.CreateInstance(__uuidof(ADODB::Connection));
hr = com.CreateInstance(__uuidof(ADODB::Command));
hr = par.CreateInstance(__uuidof(ADODB::parameter));
hr = rec.CreateInstance(__uuidof(ADODB::Record));

printf("Connection object created.\n");

// open the data source with the Connection object

sConString = L"Provider=Microsoft.Jet.OLEDB.4.0;"
L"Data Source=C:\\Users\\Mike Certini\\Documents\\Trading\\Databases\\TradingAnalysis#2.mdb";
//L"DataSchema=mytable";

// open the connection.

hr = con->Open(sConString, L"", L"", -1);

printf("Connection has been opened.\n");

// create and store SQL string for command string.

_bstr_t strSQL("INSERT INTO mytable(id,desc) VALUES(?, ?)");

// activate connection string.

com->ActiveConnection = con;

// establish command string parameters.

com->CommandText = strSQL;
com->CommandType = ADODB::adCmdText;

// Define Integer/variant.
VARIANT vtInt;
int intNum = 1;
vtInt.vt = VT_I2;
vtInt.iVal = intNum;

// Define Character/variant.
VARIANT vText;
vText.vt = VT_BSTR;
vText.bstrVal = _bstr_t("This is text");

// Complete parameter objects

hr = com->Parameters->Append(com->CreateParameter(_bstr_t("id"),ADODB::adInteger,ADODB::adParamInput,4,intNum));
hr = com->Parameters->Append(com->CreateParameter(_bstr_t("desc"),ADODB::adChar,ADODB::adParamInput,15,vText));

// Execute command object

try
{
rec = com->Execute(NULL, NULL, ADODB::adCmdStoredProc);
}
catch(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

// Print COM errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}

rec->Close( );
rec = NULL;

printf("Closed an removed the "
"Recordset object from memory.\n");

// close and remove the Connection object from memory

con->Close( );
con = NULL;

printf("Closed and removed the "
"Connection object from memory.\n");
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top