-
March 9th, 2012, 09:49 AM
#1
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
-
March 9th, 2012, 10:20 AM
#2
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!
-
March 9th, 2012, 11:58 AM
#3
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.
-
March 12th, 2012, 02:51 AM
#4
Re: ms sql insert query syntax in VS 2010 C++
Thank you Eri523
I'll try to be more careful in the future!
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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|