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. Database & SysAdmin
  3. Database
  4. Variable value in SQL Query

Variable value in SQL Query

Scheduled Pinned Locked Moved Database
databasequestion
10 Posts 4 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.
  • T Offline
    T Offline
    T RATHA KRISHNAN
    wrote on last edited by
    #1

    Hi! I've to insert a value to a column in a particular data base table on a Button Click Event. I write the following statement to execute this: SQLdb.Query("INSERT INTO Current(TeamID) values('countryId')"); countryId is an int value. I've printed and verified it. But when the click event happens and if I open the database and check for the corresponding column, only "countryId" is present(variable's name not the variable value as I expect). If I give countryId without single quotes in the statement also the result is the same. What to do to store the variable's value in to the database?

    J R P 3 Replies Last reply
    0
    • T T RATHA KRISHNAN

      Hi! I've to insert a value to a column in a particular data base table on a Button Click Event. I write the following statement to execute this: SQLdb.Query("INSERT INTO Current(TeamID) values('countryId')"); countryId is an int value. I've printed and verified it. But when the click event happens and if I open the database and check for the corresponding column, only "countryId" is present(variable's name not the variable value as I expect). If I give countryId without single quotes in the statement also the result is the same. What to do to store the variable's value in to the database?

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      Preferably using parameterised queries, but as I don't know what SQLdb is, I cant show you what code to use. However the SQL query would look like

      INSERT INTO Current(TeamID) values (@countryId)

      T 1 Reply Last reply
      0
      • J J4amieC

        Preferably using parameterised queries, but as I don't know what SQLdb is, I cant show you what code to use. However the SQL query would look like

        INSERT INTO Current(TeamID) values (@countryId)

        T Offline
        T Offline
        T RATHA KRISHNAN
        wrote on last edited by
        #3

        Hi! I'm using Sqlite. I'm calling Sqlite from C++.

        1 Reply Last reply
        0
        • T T RATHA KRISHNAN

          Hi! I've to insert a value to a column in a particular data base table on a Button Click Event. I write the following statement to execute this: SQLdb.Query("INSERT INTO Current(TeamID) values('countryId')"); countryId is an int value. I've printed and verified it. But when the click event happens and if I open the database and check for the corresponding column, only "countryId" is present(variable's name not the variable value as I expect). If I give countryId without single quotes in the statement also the result is the same. What to do to store the variable's value in to the database?

          R Offline
          R Offline
          R Giskard Reventlov
          wrote on last edited by
          #4

          Try: SQLdb.Query("INSERT INTO Current(TeamID) values(' + countryId + ')");

          "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

          T 1 Reply Last reply
          0
          • R R Giskard Reventlov

            Try: SQLdb.Query("INSERT INTO Current(TeamID) values(' + countryId + ')");

            "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

            T Offline
            T Offline
            T RATHA KRISHNAN
            wrote on last edited by
            #5

            Now + countryId + is store in the table.

            R 1 Reply Last reply
            0
            • T T RATHA KRISHNAN

              Now + countryId + is store in the table.

              R Offline
              R Offline
              R Giskard Reventlov
              wrote on last edited by
              #6

              Oops - sorry, should have been: SQLdb.Query("INSERT INTO Current(TeamID) values(" + countryId + ")"); Couldn't you have figured that out on your own?

              "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

              T 1 Reply Last reply
              0
              • R R Giskard Reventlov

                Oops - sorry, should have been: SQLdb.Query("INSERT INTO Current(TeamID) values(" + countryId + ")"); Couldn't you have figured that out on your own?

                "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                T Offline
                T Offline
                T RATHA KRISHNAN
                wrote on last edited by
                #7

                Sorry! I'm a C++ Programmer. I'm new to SQL. That's why I'm troubling you again and again. This Query is also not working. C++ shows error: C2110:Can not add two pointers.

                modified on Friday, July 30, 2010 7:23 AM

                R J 2 Replies Last reply
                0
                • T T RATHA KRISHNAN

                  Sorry! I'm a C++ Programmer. I'm new to SQL. That's why I'm troubling you again and again. This Query is also not working. C++ shows error: C2110:Can not add two pointers.

                  modified on Friday, July 30, 2010 7:23 AM

                  R Offline
                  R Offline
                  R Giskard Reventlov
                  wrote on last edited by
                  #8

                  That's as close as I can get you. I haven't used C++ for years but I'm pretty sure you could create a string object with the id inserted and pass that to the query. You must know how to do that, surely. printf or sprintf, if I recall.

                  "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

                  1 Reply Last reply
                  0
                  • T T RATHA KRISHNAN

                    Sorry! I'm a C++ Programmer. I'm new to SQL. That's why I'm troubling you again and again. This Query is also not working. C++ shows error: C2110:Can not add two pointers.

                    modified on Friday, July 30, 2010 7:23 AM

                    J Offline
                    J Offline
                    J4amieC
                    wrote on last edited by
                    #9

                    T.RATHA KRISHNAN wrote:

                    Sorry! I'm a C++ Programmer. I'm new to SQL

                    Still, you cant destinguish between a string literal and a variable?

                    1 Reply Last reply
                    0
                    • T T RATHA KRISHNAN

                      Hi! I've to insert a value to a column in a particular data base table on a Button Click Event. I write the following statement to execute this: SQLdb.Query("INSERT INTO Current(TeamID) values('countryId')"); countryId is an int value. I've printed and verified it. But when the click event happens and if I open the database and check for the corresponding column, only "countryId" is present(variable's name not the variable value as I expect). If I give countryId without single quotes in the statement also the result is the same. What to do to store the variable's value in to the database?

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #10

                      I suggest you tell your boss to hire an SQL specialist.

                      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