Richard Hudson
May 23rd, 2001, 08:10 AM
John:
Could anyone please tell me what I am doing wrong:
...
...
...
try
{
ADODB::_CommandPtr cmd;
ADODB::_ParameterPtr prmField0;
ADODB::_ParameterPtr prmField1;
ADODB::_RecordsetPtr pRstCase = NULL;
ADODB::_ConnectionPtr Conn1;
Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
Conn1->ConnectionString = _bstr_t("data source=Test1;userid=admin;password=;");
Conn1->Open( _bstr_t(L""), _bstr_t(L""), _bstr_t(L""), -1 );
cmd.CreateInstance(__uuidof(ADODB::Command));
CString tempStr;
tempStr.Format("SELECT * FROM %s","Query1");
// Test1 is a view "Query" in an access 2000 db that has 1 parameters
cmd->ActiveConnection = Conn1;
cmd->CommandText = _bstr_t(tempStr);
CString strValue(_T("2"));
prmField0 = cmd->CreateParameter(_bstr_t("Expr1"), ADODB::adBSTR, ADODB::adParamInput, -1, _variant_t(strValue.AllocSysString()));
prmField0->Value = _variant_t(strValue.AllocSysString());
cmd->Parameters->Append(prmField0);
// NOTE: The Database will ignore the parameter names so you must place the parameters in the same order as you
// have defined in your view "query".
_variant_t v1(DISP_E_PARAMNOTFOUND,VT_ERROR);
_variant_t v2(DISP_E_PARAMNOTFOUND,VT_ERROR);
pRstCase = cmd->Execute(&v1,&v2, adCmdText);
while(!pRstCase->adoEOF)
{
// Do something with the data
pRstCase->MoveNext();
}
}
catch (_com_error &e)
{
}
catch( CException* e)
{
}
catch (...)
{
}
...
...
Every time I run this I get an exception 'DB_E_PARAMNOTOPTIONAL'.
The database is a simple test DB. It has one table with one column called 'Field'.
In Microsof Access the query Criteria is called 'Expr1' just soit prompts the user and this works fine.
I just can't get it to work with ADO. I f I take the Criteria field away it just returns all the records. With it in I get 'DB_E_PARAMNOTOPTIONAL'.
Please, please if u can help me..
I am very grateful for your time.
Richard Hudson
Huddy
Could anyone please tell me what I am doing wrong:
...
...
...
try
{
ADODB::_CommandPtr cmd;
ADODB::_ParameterPtr prmField0;
ADODB::_ParameterPtr prmField1;
ADODB::_RecordsetPtr pRstCase = NULL;
ADODB::_ConnectionPtr Conn1;
Conn1.CreateInstance( __uuidof( ADODB::Connection ) );
Conn1->ConnectionString = _bstr_t("data source=Test1;userid=admin;password=;");
Conn1->Open( _bstr_t(L""), _bstr_t(L""), _bstr_t(L""), -1 );
cmd.CreateInstance(__uuidof(ADODB::Command));
CString tempStr;
tempStr.Format("SELECT * FROM %s","Query1");
// Test1 is a view "Query" in an access 2000 db that has 1 parameters
cmd->ActiveConnection = Conn1;
cmd->CommandText = _bstr_t(tempStr);
CString strValue(_T("2"));
prmField0 = cmd->CreateParameter(_bstr_t("Expr1"), ADODB::adBSTR, ADODB::adParamInput, -1, _variant_t(strValue.AllocSysString()));
prmField0->Value = _variant_t(strValue.AllocSysString());
cmd->Parameters->Append(prmField0);
// NOTE: The Database will ignore the parameter names so you must place the parameters in the same order as you
// have defined in your view "query".
_variant_t v1(DISP_E_PARAMNOTFOUND,VT_ERROR);
_variant_t v2(DISP_E_PARAMNOTFOUND,VT_ERROR);
pRstCase = cmd->Execute(&v1,&v2, adCmdText);
while(!pRstCase->adoEOF)
{
// Do something with the data
pRstCase->MoveNext();
}
}
catch (_com_error &e)
{
}
catch( CException* e)
{
}
catch (...)
{
}
...
...
Every time I run this I get an exception 'DB_E_PARAMNOTOPTIONAL'.
The database is a simple test DB. It has one table with one column called 'Field'.
In Microsof Access the query Criteria is called 'Expr1' just soit prompts the user and this works fine.
I just can't get it to work with ADO. I f I take the Criteria field away it just returns all the records. With it in I get 'DB_E_PARAMNOTOPTIONAL'.
Please, please if u can help me..
I am very grateful for your time.
Richard Hudson
Huddy