CADODatabase class: Currency parameters in SQL
-
This question is for anyone using the CADODatabase classes in codeproject.com:
I'm trying to pass a currency amount to a SQL command and keep getting an exception about not declaring scalar variable @Amount. Any ideas about what is wrong?
CADORecordset \*pRecSet=new CADORecordset(pDB); // search for amount $28050.65 CADOCommand \*pCmd=new CADOCommand(pDB, "select itemid from item where amount=@Amount", CADOCommand::typeCmdText); COleCurrency currency; currency.m\_cur.int64=280506500; \_variant\_t vtValue; vtValue.vt=VT\_CY; vtValue.cyVal=currency.m\_cur; pCmd->AddParameter("@Amount", CADORecordset::typeCurrency, CADOParameter::paramInput, 8, vtValue, 0, 0); if(pRecSet->Execute(pCmd)) { // exception gets thrown by Execute(pCmd) } pRecSet->Close(); delete pCmd; delete pRecSet;
-
This question is for anyone using the CADODatabase classes in codeproject.com:
I'm trying to pass a currency amount to a SQL command and keep getting an exception about not declaring scalar variable @Amount. Any ideas about what is wrong?
CADORecordset \*pRecSet=new CADORecordset(pDB); // search for amount $28050.65 CADOCommand \*pCmd=new CADOCommand(pDB, "select itemid from item where amount=@Amount", CADOCommand::typeCmdText); COleCurrency currency; currency.m\_cur.int64=280506500; \_variant\_t vtValue; vtValue.vt=VT\_CY; vtValue.cyVal=currency.m\_cur; pCmd->AddParameter("@Amount", CADORecordset::typeCurrency, CADOParameter::paramInput, 8, vtValue, 0, 0); if(pRecSet->Execute(pCmd)) { // exception gets thrown by Execute(pCmd) } pRecSet->Close(); delete pCmd; delete pRecSet;
-
I presume you are referring to A set of ADO classes - version 2.20[^]. In which case you should post your question to the article forum. Although it appears the author is no longer active here.
That's why I asked here, sorry if it wasn't the appropriate place. I was hoping someone was actually using the code and could point me in the right direction.
-
That's why I asked here, sorry if it wasn't the appropriate place. I was hoping someone was actually using the code and could point me in the right direction.
You may be lucky, but it still requires someone who really understands the code. From my quick look at the article it would take some considerable time to reach that stage. Do you really need this code, or is there an alternative way of solving your problem?
-
You may be lucky, but it still requires someone who really understands the code. From my quick look at the article it would take some considerable time to reach that stage. Do you really need this code, or is there an alternative way of solving your problem?
The code should work, every example I've seen on the internet with ADO is making identical COM calls. I was hoping there was a trick (it's Microsoft after all) to making it work.
-
You may be lucky, but it still requires someone who really understands the code. From my quick look at the article it would take some considerable time to reach that stage. Do you really need this code, or is there an alternative way of solving your problem?
I think I may have stumbled onto the answer. Seems ADO may not be able to handle parameterized SQL statements since I can pass currency values to a stored procedure call. Thank you for your time in replying to question. Please close the question.