ms sql insert query syntax in VS 2010 C++
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: ms sql insert query syntax in VS 2010 C++

  1. #1
    Join Date
    Mar 2012
    Posts
    3

    ms sql insert query syntax in VS 2010 C++

    Hello everyone.
    Im trying to create a cmd application in VS2010 C++,in which i will read some integer values and insert them into a table in MS SQL server. For the connection of the application with the server i use ODBC.

    If i use something like the following, i get results (insert is working):

    if(SQL_SUCCESS!=SQLExecDirect(sqlstatementhandle,(SQLCHAR*)"INSERT INTO MyTable(value1) VALUES (111)", SQL_NTS)){
    show_error(SQL_HANDLE_STMT, sqlstatementhandle);

    }

    after the execution of the code above if i check the database i can see that insert worked just fine. Can someone tell me how i can use variables in the insert query, instead of numbers(like 111 above)?

    Also since i couldnt find the proper syntax of insert with integer variables, i tried to create a stringstream(concatenating the insert command with the integer variables), which i later convert to string and use it in my sql command. Unfortunately it doesnt work either!

    can someone help please?
    thank you

  2. #2
    Join Date
    Mar 2012
    Posts
    3

    Re: ms sql insert query syntax in VS 2010 C++

    hello again...
    i think i managed to find a solution to my problem- but without finding the proper syntax for insert:

    SQLCHAR SQLStmt[100];

    sprintf((char*)SQLStmt,"INSERT INTO MyTable(value1) VALUES (%d);",int_var);


    if(SQL_SUCCESS!=SQLExecDirect(sqlstatementhandle,SQLStmt, SQL_NTS)){
    show_error(SQL_HANDLE_STMT, sqlstatementhandle);

    }


    i will proceed with my application for now, if anyone knows the answer to my question please let me know!
    cheers!

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,585

    Arrow Re: ms sql insert query syntax in VS 2010 C++

    I think this definitely is no C++/CLI question, so this is the wrong forum section here. It doesn't seem to really be concerned with native C++ either, so I think the best place to ask is the Database section.

    At any rate, welcome to CodeGuru!
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  4. #4
    Join Date
    Mar 2012
    Posts
    3

    Re: ms sql insert query syntax in VS 2010 C++

    Thank you Eri523
    I'll try to be more careful in the future!

    Quote Originally Posted by Eri523 View Post
    I think this definitely is no C++/CLI question, so this is the wrong forum section here. It doesn't seem to really be concerned with native C++ either, so I think the best place to ask is the Database section.

    At any rate, welcome to CodeGuru!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center