Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CADODatabase class: Currency parameters in SQL

CADODatabase class: Currency parameters in SQL

Scheduled Pinned Locked Moved C / C++ / MFC
questiondatabasecom
6 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Don Stauffer
    wrote on last edited by
    #1

    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;
    
    L 1 Reply Last reply
    0
    • D Don Stauffer

      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;
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • L Lost User

        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.

        D Offline
        D Offline
        Don Stauffer
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • D Don Stauffer

          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.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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?

          D 2 Replies Last reply
          0
          • L Lost User

            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?

            D Offline
            D Offline
            Don Stauffer
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • L Lost User

              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?

              D Offline
              D Offline
              Don Stauffer
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups