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 insert data in sqlserver 2005 using vc++6.0

how to insert data in sqlserver 2005 using vc++6.0

Scheduled Pinned Locked Moved C / C++ / MFC
databasec++tutorial
3 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.
  • E Offline
    E Offline
    eswar pothula
    wrote on last edited by
    #1

    hi everybody. in my vc++ application cannot insert data into database.... success fully inserting to passing values...using this code line SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(222,'shan',5676)" ,SQL_NTS); but using varibles(dynamically) cannot inserting. SQLINTEGER empnum=1006; SQLVARCHAR ename[20]="weewe"; SQLFLOAT esal=5656; SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(empnum,'ename',esal)",SQL_NTS); please solve this porblem...... thanks in advance......

    S CPalliniC 2 Replies Last reply
    0
    • E eswar pothula

      hi everybody. in my vc++ application cannot insert data into database.... success fully inserting to passing values...using this code line SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(222,'shan',5676)" ,SQL_NTS); but using varibles(dynamically) cannot inserting. SQLINTEGER empnum=1006; SQLVARCHAR ename[20]="weewe"; SQLFLOAT esal=5656; SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(empnum,'ename',esal)",SQL_NTS); please solve this porblem...... thanks in advance......

      S Offline
      S Offline
      super
      wrote on last edited by
      #2

      eswar pothula wrote:

      SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(empnum,'ename',esal)",SQL_NTS);

      Code is treating (empnum,'ename',esal)as the values and not as variable...So this code tries to insert string into Interger data type for the colum Emp number and salary and so it errors out If you want to dynamically assign the values, my sugesstion would be bind the parameters using

      SQLBindParameter

      and execute using

      SQLExecute

      cheers, Super ------------------------------------------ Too much of good is bad,mix some evil in it

      modified on Tuesday, November 3, 2009 5:21 AM

      1 Reply Last reply
      0
      • E eswar pothula

        hi everybody. in my vc++ application cannot insert data into database.... success fully inserting to passing values...using this code line SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(222,'shan',5676)" ,SQL_NTS); but using varibles(dynamically) cannot inserting. SQLINTEGER empnum=1006; SQLVARCHAR ename[20]="weewe"; SQLFLOAT esal=5656; SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(empnum,'ename',esal)",SQL_NTS); please solve this porblem...... thanks in advance......

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

        eswar pothula wrote:

        SQLExecDirect(hstmt,(unsigned char *)"insert into emp values(empnum,'ename',esal)",SQL_NTS);

        That's wrong. Try to change it to:

        const int SIZE = 256;
        char sqlcmd[SIZE];
        sprintf(sqlcmd, "insert into emp values(%d,'%s',%f)", empnum, ename, esal);
        SQLExecDirect(hstmt,(unsigned char *) sqlcmd, SQL_NTS);

        of course, in real life, you should check for buffer overruns, etc... :)

        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]

        In testa che avete, signor di Ceprano?

        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