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. I have to insert value into table at runtime ?

I have to insert value into table at runtime ?

Scheduled Pinned Locked Moved C / C++ / MFC
databasetutorialquestion
6 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.
  • J Offline
    J Offline
    jadhavjitendrar
    wrote on last edited by
    #1

    CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..

    modified on Monday, September 14, 2009 6:37 AM

    _ C 2 Replies Last reply
    0
    • J jadhavjitendrar

      CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..

      modified on Monday, September 14, 2009 6:37 AM

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      Use CString::Format[^] to create the string.

      CString cs;
      cs.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, strAnsi);

      «_Superman_» I love work. It gives me something to do between weekends.

      J 1 Reply Last reply
      0
      • J jadhavjitendrar

        CSting strid = m_strStringArr.getat(i); T("INSERT INTO tablename (setid) VALUES('strAnsi')"); This is my query and i get table field and its value at runtime.So how to insert this value.any idea about it..means Setid and stransi i get at runtime..

        modified on Monday, September 14, 2009 6:37 AM

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        Do you really :omg: mean this

        CString strTable = _T("MyRuntimeValueForTable");
        CString strData = _T("MyRuntimeValueForData");

        CString strQuery;
        strQuery.Format(_T("INSERT INTO %s VALUES ('%s')"), strTable, strData);

        ?

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • _ _Superman_

          Use CString::Format[^] to create the string.

          CString cs;
          cs.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, strAnsi);

          «_Superman_» I love work. It gives me something to do between weekends.

          J Offline
          J Offline
          jadhavjitendrar
          wrote on last edited by
          #4

          It Works.. Thanks Superman

          J 1 Reply Last reply
          0
          • J jadhavjitendrar

            It Works.. Thanks Superman

            J Offline
            J Offline
            jadhavjitendrar
            wrote on last edited by
            #5

            But after set this data to fields,every fields ti goes into new line.i dont want this.I want after new line it goes to next line or next record.So how to solve this problem..

            N 1 Reply Last reply
            0
            • J jadhavjitendrar

              But after set this data to fields,every fields ti goes into new line.i dont want this.I want after new line it goes to next line or next record.So how to solve this problem..

              N Offline
              N Offline
              norish
              wrote on last edited by
              #6

              When strAnsi has _T("aaa\nbbb\nccc") then want to make 3 records? Do you mean like this? If then, you must split strAnsi at first and make and execute sql 3 times. For example;

              TCHAR* strData = strAnsi.GetBuffer(-1);
              TCHAR* pToken = _tcstok(strAnsi, _T("\n"));
              while (pToken) {
              CString sql;
              sql.Format(_T("INSERT INTO tablename (%s) VALUES('%s')"), setid, pToken);
              // execute SQL here
              }
              strAnsi.ReleaseBuffer();

              Well, I dont feel good VALUES('%s') in above sql because of string escaping issue or SQL-injection problems. I usually use prepared statements or parameterized query for this purpose.

              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