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
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!
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! :)
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
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! :)