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. CDatabase::ExecuteSQL

CDatabase::ExecuteSQL

Scheduled Pinned Locked Moved C / C++ / MFC
helpdatabase
8 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.
  • F Offline
    F Offline
    Fawaz Ajani
    wrote on last edited by
    #1

    Hi everybody! I'm creating a program which use database. My problem is: I use ExecuteSQl() to input data into my database but when i run it, I show an error "too few parameters. Expected 1".

    CString path(_T("\',\'")), pathInt(_T("','"), rien(_T("NUL"));
    //personne(nom, prenoms, datNais, lieuNais, domicile,commNais, numPiece, sexe, profession, nationalite, numPersP, numPersM)
    reqPer = _T("insert into personne values (2014,\'") + nomPer + path + prenPer + path + datNaissPer + path + liNaisPer + path + domPer + _T("\',") + rien + _T(",\'") + numPiecPer + path + _T('M') + path + profPer + path + natPer + _T("\',") + rien + pathInt + rien + _T(")");
    database.ExecuteSQL(reqPer);

    L F 2 Replies Last reply
    0
    • F Fawaz Ajani

      Hi everybody! I'm creating a program which use database. My problem is: I use ExecuteSQl() to input data into my database but when i run it, I show an error "too few parameters. Expected 1".

      CString path(_T("\',\'")), pathInt(_T("','"), rien(_T("NUL"));
      //personne(nom, prenoms, datNais, lieuNais, domicile,commNais, numPiece, sexe, profession, nationalite, numPersP, numPersM)
      reqPer = _T("insert into personne values (2014,\'") + nomPer + path + prenPer + path + datNaissPer + path + liNaisPer + path + domPer + _T("\',") + rien + _T(",\'") + numPiecPer + path + _T('M') + path + profPer + path + natPer + _T("\',") + rien + pathInt + rien + _T(")");
      database.ExecuteSQL(reqPer);

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

      You should check the final value of the reqPer string to see whether the SQL command is correctly formed. I would also strongly suggest you do not create SQL statements in the way you have done, as this leaves your code open to SQL injection, and the potential loss or corruption of your database. See the CRecordSet class[^] for the correct way to do it.

      F 1 Reply Last reply
      0
      • L Lost User

        You should check the final value of the reqPer string to see whether the SQL command is correctly formed. I would also strongly suggest you do not create SQL statements in the way you have done, as this leaves your code open to SQL injection, and the potential loss or corruption of your database. See the CRecordSet class[^] for the correct way to do it.

        F Offline
        F Offline
        Fawaz Ajani
        wrote on last edited by
        #3

        I saw it, but it's not very clear for me. Please, can you post a sample?!

        L D 2 Replies Last reply
        0
        • F Fawaz Ajani

          I saw it, but it's not very clear for me. Please, can you post a sample?!

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

          Fawaz Ajani wrote:

          Please, can you post a sample?

          Sorry, I don't have one. You need to either search for yourself, or spend time reading the documentation.

          F 1 Reply Last reply
          0
          • F Fawaz Ajani

            I saw it, but it's not very clear for me. Please, can you post a sample?!

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

            This article does not do any writing or updating, but it may help to point you in the right direction.

            "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

            "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

            F 1 Reply Last reply
            0
            • L Lost User

              Fawaz Ajani wrote:

              Please, can you post a sample?

              Sorry, I don't have one. You need to either search for yourself, or spend time reading the documentation.

              F Offline
              F Offline
              Fawaz Ajani
              wrote on last edited by
              #6

              It will be correct, if i use this one?

              sql.Format("INSERT INTO NomTable (Colone1,Colonn2, ....) VALUES(%d ,'%s','%s', ....)",m_Variable1,m_Variable2, ....);
              db->ExecuteSQL(sql);

              1 Reply Last reply
              0
              • D David Crow

                This article does not do any writing or updating, but it may help to point you in the right direction.

                "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

                "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                F Offline
                F Offline
                Fawaz Ajani
                wrote on last edited by
                #7

                thanks

                1 Reply Last reply
                0
                • F Fawaz Ajani

                  Hi everybody! I'm creating a program which use database. My problem is: I use ExecuteSQl() to input data into my database but when i run it, I show an error "too few parameters. Expected 1".

                  CString path(_T("\',\'")), pathInt(_T("','"), rien(_T("NUL"));
                  //personne(nom, prenoms, datNais, lieuNais, domicile,commNais, numPiece, sexe, profession, nationalite, numPersP, numPersM)
                  reqPer = _T("insert into personne values (2014,\'") + nomPer + path + prenPer + path + datNaissPer + path + liNaisPer + path + domPer + _T("\',") + rien + _T(",\'") + numPiecPer + path + _T('M') + path + profPer + path + natPer + _T("\',") + rien + pathInt + rien + _T(")");
                  database.ExecuteSQL(reqPer);

                  F Offline
                  F Offline
                  Fawaz Ajani
                  wrote on last edited by
                  #8

                  Please, I have order problem. when I do this:

                  CRecordset recordset(&database);
                  CString temp, query;
                  query.Format(L"SELECT number FROM personne WHERE numPiece = '%s'", numPiecPer);
                  recordset.Open(CRecordset::snapshot, query, CRecordset::appendOnly);
                  while (!recordset.IsEOF())
                  {
                  recordset.GetFieldValue((short)0, temp);
                  messageBox(temp, 0, 0);
                  recordset.MoveNext();
                  }

                  It don't work. :(

                  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