Vandana Sood
August 3rd, 2000, 03:11 PM
I have the following code which works perfectly with SQL server.In Access it works perfectly for a select query.But the moment I change it to an Insert/Update/Delete query it fails at parameter binding.Can someone tell me what has to be done?
int li_Error = 0;
My code for the function is:
try{
HRESULT lhr;
//Create a command Ptr
_CommandPtr l_pCommand;
CREATE_INSTANCE(l_pCommand,Command)
//Check whether the Connection is available else raise error.
if ((mPv_pConnectionPtr == NULL)&(mPv_pConnectionPtr->State != adStateOpen))
return S_FALSE;
//Set the Active Connection on the Command
l_pCommand->ActiveConnection = mPv_pConnectionPtr;
//Set the commandtype to stored procedure as you want to use a storedprocedure
l_pCommand->CommandType = adCmdTable;
//set the command text to the stored proc name
l_pCommand->CommandText = pSPName;
//Execute the Stored Procedure
VARIANT l_Var;
VariantInit(&l_Var);
//check whether the array passed is single dim or two dim
//if two dim call in a loop else once.
long ll_NoOfDim = _pInputParm->parray->cDims;
if ( ll_NoOfDim == 1)
{
l_pCommand->Parameters->Refresh();
long paramcount = p_pInputParm->parray>rgsabound->cElements;
for(long l_ColCount=0;l_ColCountparray,&l_ColCount,&l_Var);
PUT_CMD_PARAM(l_pCommand,(l_ColCount)) = l_Var;
VariantClear(&l_Var);
}
// pRs = l_pCommand->Execute(&vtMissing,&vtMissing,adCmdTable);
l_pCommand->Execute(&vtMissing,&vtMissing,adExecuteNoRecords);
}
else if( ll_NoOfDim == 2)
{
long l_ArrayIndex[2];
long ll_rowcount = p_pInputParm->parray->rgsabound[1].cElements;
l_pCommand->Parameters->Refresh();
long paramcount = p_pInputParm->parray->rgsabound[0].cElements;
for (long ll_row = 0; ll_row < ll_rowcount; ll_row++)
{
l_ArrayIndex[0] = ll_row;
for(long l_ColCount=0;l_ColCountparray,l_ArrayIndex,&l_Var);
PUT_CMD_PARAM(l_pCommand,(l_ColCount)) = l_Var;
VariantClear(&l_Var);
}
l_pCommand->Execute(&vtMissing,&vtMissing,adExecuteNoRecords);
}
}
else
return E_FAIL;
}
catch (_com_error pobj_ComError)
{
SetError(pobj_ComError,li_Error);
return S_FALSE;
}
return S_OK;
int li_Error = 0;
My code for the function is:
try{
HRESULT lhr;
//Create a command Ptr
_CommandPtr l_pCommand;
CREATE_INSTANCE(l_pCommand,Command)
//Check whether the Connection is available else raise error.
if ((mPv_pConnectionPtr == NULL)&(mPv_pConnectionPtr->State != adStateOpen))
return S_FALSE;
//Set the Active Connection on the Command
l_pCommand->ActiveConnection = mPv_pConnectionPtr;
//Set the commandtype to stored procedure as you want to use a storedprocedure
l_pCommand->CommandType = adCmdTable;
//set the command text to the stored proc name
l_pCommand->CommandText = pSPName;
//Execute the Stored Procedure
VARIANT l_Var;
VariantInit(&l_Var);
//check whether the array passed is single dim or two dim
//if two dim call in a loop else once.
long ll_NoOfDim = _pInputParm->parray->cDims;
if ( ll_NoOfDim == 1)
{
l_pCommand->Parameters->Refresh();
long paramcount = p_pInputParm->parray>rgsabound->cElements;
for(long l_ColCount=0;l_ColCountparray,&l_ColCount,&l_Var);
PUT_CMD_PARAM(l_pCommand,(l_ColCount)) = l_Var;
VariantClear(&l_Var);
}
// pRs = l_pCommand->Execute(&vtMissing,&vtMissing,adCmdTable);
l_pCommand->Execute(&vtMissing,&vtMissing,adExecuteNoRecords);
}
else if( ll_NoOfDim == 2)
{
long l_ArrayIndex[2];
long ll_rowcount = p_pInputParm->parray->rgsabound[1].cElements;
l_pCommand->Parameters->Refresh();
long paramcount = p_pInputParm->parray->rgsabound[0].cElements;
for (long ll_row = 0; ll_row < ll_rowcount; ll_row++)
{
l_ArrayIndex[0] = ll_row;
for(long l_ColCount=0;l_ColCountparray,l_ArrayIndex,&l_Var);
PUT_CMD_PARAM(l_pCommand,(l_ColCount)) = l_Var;
VariantClear(&l_Var);
}
l_pCommand->Execute(&vtMissing,&vtMissing,adExecuteNoRecords);
}
}
else
return E_FAIL;
}
catch (_com_error pobj_ComError)
{
SetError(pobj_ComError,li_Error);
return S_FALSE;
}
return S_OK;