ADO To MS Access Database.
-
I am having problems with executing a command object in ADO. The specific problem I have revolves around the proper type for the SQL string. Following examples on the internet, I established it with a _bstr_t. This though is not working with the * VARIANT type that is required in the Execute method. Can someone help me with the proper establishment of the SQL string? Listed below is the complete program: Here is my error message coming out of the try block: error C2664: 'ADODB::Command15::Execute' : cannot convert parameter 1 from '_bstr_t' to 'VARIANT *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
#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 objectsADODB::\_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(sC
-
I am having problems with executing a command object in ADO. The specific problem I have revolves around the proper type for the SQL string. Following examples on the internet, I established it with a _bstr_t. This though is not working with the * VARIANT type that is required in the Execute method. Can someone help me with the proper establishment of the SQL string? Listed below is the complete program: Here is my error message coming out of the try block: error C2664: 'ADODB::Command15::Execute' : cannot convert parameter 1 from '_bstr_t' to 'VARIANT *' 1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
#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 objectsADODB::\_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(sC
Hi, Few observations: - your command type shouldn't be
adCmdStoredProc
since you're executing a normal DML statement. UseadCmdText
instead. - the SQL statement for insert should contain the VALUES section and the parameters to use, like:_bstr_t strSQL("INSERT INTO mytable(id,desc) VALUES (?, ?)");
- the execute contains the SQL statement as a parameter. I'm not sure if there's such overload, normally the first parameter is the number of records affected, see: http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx[^]
The need to optimize rises from a bad design.My articles[^]
-
Hi, Few observations: - your command type shouldn't be
adCmdStoredProc
since you're executing a normal DML statement. UseadCmdText
instead. - the SQL statement for insert should contain the VALUES section and the parameters to use, like:_bstr_t strSQL("INSERT INTO mytable(id,desc) VALUES (?, ?)");
- the execute contains the SQL statement as a parameter. I'm not sure if there's such overload, normally the first parameter is the number of records affected, see: http://msdn.microsoft.com/en-us/library/ms681559(VS.85).aspx[^]
The need to optimize rises from a bad design.My articles[^]
Mika, Thank you for your response. After making the changes you suggested I get the following error. Instead of the "Records Affected" parameter, I have input "NULL". As a result, I am getting this error: Connection object created. Connection has been opened. Error Code = 80040e14 Code meaning = I Source = Microsoft JET Database Engine Description = Expected query name after EXECUTE.
-
Mika, Thank you for your response. After making the changes you suggested I get the following error. Instead of the "Records Affected" parameter, I have input "NULL". As a result, I am getting this error: Connection object created. Connection has been opened. Error Code = 80040e14 Code meaning = I Source = Microsoft JET Database Engine Description = Expected query name after EXECUTE.
Hi, Could be some kind of syntax issue in the SQL statement itself. Also if I rememeber correctly the parameter usage in the sql statement may be provider specific so if the SQL statement is otherwise fine could it be because of the question mark. You could try literals as a test n order to see if that's the case. Also perhaps the following link would help you: http://msdn.microsoft.com/en-us/library/ms677554(v=VS.85).aspx[^]
The need to optimize rises from a bad design.My articles[^]