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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Database Syntax

Database Syntax

Scheduled Pinned Locked Moved C / C++ / MFC
databasemysqlquestion
17 Posts 6 Posters 4 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.
  • G gregarion

    Hey guys I want to insert values into a MySql database. The following line works fine:

    mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')");

    but if the data to be inserted is from a string... like....

    string NewTitle = "Monaco";
    string NumofShows = "2";

    What can i do so it will be able to read the strings and use their values to be inserted into the data table?

    T Offline
    T Offline
    ThatsAlok
    wrote on last edited by
    #2

    CString.Format can help in this!

    "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
    Never mind - my own stupidity is the source of every "problem" - Mixture

    cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

    G 1 Reply Last reply
    0
    • G gregarion

      Hey guys I want to insert values into a MySql database. The following line works fine:

      mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')");

      but if the data to be inserted is from a string... like....

      string NewTitle = "Monaco";
      string NumofShows = "2";

      What can i do so it will be able to read the strings and use their values to be inserted into the data table?

      G Offline
      G Offline
      Game point
      wrote on last edited by
      #3

      try char* NewTitle = "Monaco"; char* NumofShows = "2";

      :~ Failure is Success If we learn from it!!:~

      G 1 Reply Last reply
      0
      • T ThatsAlok

        CString.Format can help in this!

        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
        Never mind - my own stupidity is the source of every "problem" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        G Offline
        G Offline
        gregarion
        wrote on last edited by
        #4

        Could you explain how i can insert it into my sql query to show how it works?

        1 Reply Last reply
        0
        • G Game point

          try char* NewTitle = "Monaco"; char* NumofShows = "2";

          :~ Failure is Success If we learn from it!!:~

          G Offline
          G Offline
          gregarion
          wrote on last edited by
          #5

          Sorry, i do not get u? i mean, how do we insert the variables "NewTitle" and "NumofShows" into the sql statement so it can read the varaibles..

          G 1 Reply Last reply
          0
          • G gregarion

            Sorry, i do not get u? i mean, how do we insert the variables "NewTitle" and "NumofShows" into the sql statement so it can read the varaibles..

            G Offline
            G Offline
            Game point
            wrote on last edited by
            #6

            mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")

            char* NewTitle = "Monaco"; char* NumofShows = "2"; CString InsertQuery= "INSERT INTO main (" + (CString)NumofShows +","+(CString) NewTitle +") VALUES('12', 'Home')"; mysql_query(connection,InsertQuery); before that change your project properties unicode into multibyte ..i hope this ll work ..if any error comes send it !!!

            :~ Failure is Success If we learn from it!!:~

            G 1 Reply Last reply
            0
            • G Game point

              mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")

              char* NewTitle = "Monaco"; char* NumofShows = "2"; CString InsertQuery= "INSERT INTO main (" + (CString)NumofShows +","+(CString) NewTitle +") VALUES('12', 'Home')"; mysql_query(connection,InsertQuery); before that change your project properties unicode into multibyte ..i hope this ll work ..if any error comes send it !!!

              :~ Failure is Success If we learn from it!!:~

              G Offline
              G Offline
              gregarion
              wrote on last edited by
              #7

              mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")

              Sorry i think you misunderstood what i meant. Normally, for the values, it has to be hardcoded in, for example, having to put 12 and home inside. What i meant is, for example, if the values to be inserted are in a variable , like .. string NewShowName = "Danger" int NewNumberofShow = "2" How do i put in this variables (NewShowName, NewNumberofShow) into the sql statements at VALUES so the program can read the values inside this variables and then save them in the database

              L D 2 Replies Last reply
              0
              • G gregarion

                mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")

                Sorry i think you misunderstood what i meant. Normally, for the values, it has to be hardcoded in, for example, having to put 12 and home inside. What i meant is, for example, if the values to be inserted are in a variable , like .. string NewShowName = "Danger" int NewNumberofShow = "2" How do i put in this variables (NewShowName, NewNumberofShow) into the sql statements at VALUES so the program can read the values inside this variables and then save them in the database

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

                Might I suggest you will probably get a better response in the Database forum for this question.

                MVP 2010 - are they mad?

                1 Reply Last reply
                0
                • G gregarion

                  mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')")

                  Sorry i think you misunderstood what i meant. Normally, for the values, it has to be hardcoded in, for example, having to put 12 and home inside. What i meant is, for example, if the values to be inserted are in a variable , like .. string NewShowName = "Danger" int NewNumberofShow = "2" How do i put in this variables (NewShowName, NewNumberofShow) into the sql statements at VALUES so the program can read the values inside this variables and then save them in the database

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #9

                  If you are using MFC, try:

                  CString strQuery;
                  strQuery.Format("INSERT INTO main (NumofShows , Title) VALUES('%d', '%s')", number, title);

                  If not, you can use the same format with sprintf();

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "Man who follows car will be exhausted." - Confucius

                  G 1 Reply Last reply
                  0
                  • G gregarion

                    Hey guys I want to insert values into a MySql database. The following line works fine:

                    mysql_query(connection, "INSERT INTO main (NumofShows , Title) VALUES('12', 'Home')");

                    but if the data to be inserted is from a string... like....

                    string NewTitle = "Monaco";
                    string NumofShows = "2";

                    What can i do so it will be able to read the strings and use their values to be inserted into the data table?

                    M Offline
                    M Offline
                    Maximilien
                    wrote on last edited by
                    #10

                    Why did you removed your message ? Other people cannot learn from your experience because they do not know the question.

                    This signature was proudly tested on animals.

                    1 Reply Last reply
                    0
                    • D David Crow

                      If you are using MFC, try:

                      CString strQuery;
                      strQuery.Format("INSERT INTO main (NumofShows , Title) VALUES('%d', '%s')", number, title);

                      If not, you can use the same format with sprintf();

                      "One man's wage rise is another man's price increase." - Harold Wilson

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      "Man who follows car will be exhausted." - Confucius

                      G Offline
                      G Offline
                      gregarion
                      wrote on last edited by
                      #11

                      What is MFC and what does "%d" and "%s" stands for?

                      D 1 Reply Last reply
                      0
                      • G gregarion

                        What is MFC and what does "%d" and "%s" stands for?

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #12

                        gregarion wrote:

                        What is MFC...

                        See here and here.

                        gregarion wrote:

                        ...what does "%d" and "%s" stands for?

                        See here.

                        "One man's wage rise is another man's price increase." - Harold Wilson

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        "Man who follows car will be exhausted." - Confucius

                        G 1 Reply Last reply
                        0
                        • D David Crow

                          gregarion wrote:

                          What is MFC...

                          See here and here.

                          gregarion wrote:

                          ...what does "%d" and "%s" stands for?

                          See here.

                          "One man's wage rise is another man's price increase." - Harold Wilson

                          "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                          "Man who follows car will be exhausted." - Confucius

                          G Offline
                          G Offline
                          gregarion
                          wrote on last edited by
                          #13

                          Im using netbeans. i dont think there are such libraries

                          D 1 Reply Last reply
                          0
                          • G gregarion

                            Im using netbeans. i dont think there are such libraries

                            D Offline
                            D Offline
                            David Crow
                            wrote on last edited by
                            #14

                            gregarion wrote:

                            Im using netbeans.

                            So do you have a C or C++ question?

                            "One man's wage rise is another man's price increase." - Harold Wilson

                            "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                            "Man who follows car will be exhausted." - Confucius

                            G 1 Reply Last reply
                            0
                            • D David Crow

                              gregarion wrote:

                              Im using netbeans.

                              So do you have a C or C++ question?

                              "One man's wage rise is another man's price increase." - Harold Wilson

                              "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                              "Man who follows car will be exhausted." - Confucius

                              G Offline
                              G Offline
                              gregarion
                              wrote on last edited by
                              #15

                              C++

                              M T 2 Replies Last reply
                              0
                              • G gregarion

                                C++

                                M Offline
                                M Offline
                                Maximilien
                                wrote on last edited by
                                #16

                                I sense a big failure soon.

                                This signature was proudly tested on animals.

                                1 Reply Last reply
                                0
                                • G gregarion

                                  C++

                                  T Offline
                                  T Offline
                                  ThatsAlok
                                  wrote on last edited by
                                  #17

                                  _sprintf will solve your problem then

                                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                                  Never mind - my own stupidity is the source of every "problem" - Mixture

                                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                                  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