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. how to take the result of a select query into a variable?

how to take the result of a select query into a variable?

Scheduled Pinned Locked Moved C / C++ / MFC
databasehelptutorialquestion
5 Posts 3 Posters 0 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.
  • V Offline
    V Offline
    vcseeker
    wrote on last edited by
    #1

    hi all, i am trying to run a query like this ---- CDatabase database; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "c:\\MDD.mdb"; sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { database.Open(NULL,false,false,sDsn); } CATCH(CDBException, e) { } END_CATCH database.ExecuteSQL("SELECT MAX(dist) INTO temp FROM TempTable"); *********************************************************************** TempTable is a dynamically generated temporary table.My problem is that i need to get the result of the above query into a variable. any help to solve this problem will be appreciated.... Thanks and regards.

    D C 2 Replies Last reply
    0
    • V vcseeker

      hi all, i am trying to run a query like this ---- CDatabase database; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "c:\\MDD.mdb"; sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { database.Open(NULL,false,false,sDsn); } CATCH(CDBException, e) { } END_CATCH database.ExecuteSQL("SELECT MAX(dist) INTO temp FROM TempTable"); *********************************************************************** TempTable is a dynamically generated temporary table.My problem is that i need to get the result of the above query into a variable. any help to solve this problem will be appreciated.... Thanks and regards.

      D Offline
      D Offline
      Daniel Turini
      wrote on last edited by
      #2

      vcseeker wrote: database.ExecuteSQL("SELECT MAX(dist) INTO temp FROM TempTable"); Probably, in your query, you don't want to mean "INTO temp", you want to mean "AS TEMP". "INTO temp" creates a temporary table and does not return any record. "AS temp" names the column MAX(dist) as "temp". ORACLE One Real A$#h%le Called Lary Ellison

      V 1 Reply Last reply
      0
      • D Daniel Turini

        vcseeker wrote: database.ExecuteSQL("SELECT MAX(dist) INTO temp FROM TempTable"); Probably, in your query, you don't want to mean "INTO temp", you want to mean "AS TEMP". "INTO temp" creates a temporary table and does not return any record. "AS temp" names the column MAX(dist) as "temp". ORACLE One Real A$#h%le Called Lary Ellison

        V Offline
        V Offline
        vcseeker
        wrote on last edited by
        #3

        hi Daniel, Thanks for quick reply. Actuall i am running the Query-- database.ExecuteSQL("SELECT MAX(dist) FROM TempTable"); and i want to get the result in a local variable that is declared inside my function .I want to assign the value of MAX(dist) into this local vaiable. something like this... int local; local = database.ExecuteSQL("SELECT MAX(dist) FROM TempTable");//I Wish i could be able to do that. Can you help me in achieving this. Regards.

        1 Reply Last reply
        0
        • V vcseeker

          hi all, i am trying to run a query like this ---- CDatabase database; CString sDriver = "MICROSOFT ACCESS DRIVER (*.mdb)"; CString sDsn; CString sFile = "c:\\MDD.mdb"; sDsn.Format("ODBC;DRIVER={%s};DSN='';DBQ=%s",sDriver,sFile); TRY { database.Open(NULL,false,false,sDsn); } CATCH(CDBException, e) { } END_CATCH database.ExecuteSQL("SELECT MAX(dist) INTO temp FROM TempTable"); *********************************************************************** TempTable is a dynamically generated temporary table.My problem is that i need to get the result of the above query into a variable. any help to solve this problem will be appreciated.... Thanks and regards.

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          Just a suggestion: perhaps use the CRecordset class to navigate and getting data from your records. Take a look at the MSDN documentation. Hope this helps.

          V 1 Reply Last reply
          0
          • C Cedric Moonen

            Just a suggestion: perhaps use the CRecordset class to navigate and getting data from your records. Take a look at the MSDN documentation. Hope this helps.

            V Offline
            V Offline
            vcseeker
            wrote on last edited by
            #5

            Thanks all,i solved the problem using CRecordset.

            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