TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Melissa
NA
3
0
Add String Variable to MySQL Statement in C#
Apr 11 2009 1:04 AM
Hi everyone,
I'm a C# newbie. I've done a thorough search on Google, but I still can't seem to find a fitting solution to this very simple problem.
I'm simply trying to insert a string variable into an SQL INSERT statement. Problem is, I can't seem to get the syntax right (even after viewing this solution: http://www.c-sharpcorner.com/Forums/ShowMessages.aspx?ThreadID=41667).
Here's the code:
string dataSetName = textBox1.Text;
string insertQuery = "INSERT INTO ntxy1 values (" + n + "," + t + "," + x + "," + y + "," + "'dataSetName'" + ");";
What gets added as of now is the value "dataSetName" and not the actual value of the variable dataSetName (which is whatever is inputted in textBox1).
I know that the problem has to do with dataSetName being a string variable because all the other variables (n, t, x, and y), which are ints, work fine.
Hope my question is clear enough.
I'm pretty sure I'm just getting something wrong with the syntax. Any help?
Thanks in advance!
Reply
Answers (
4
)
Sql blndr Que?
C# with SQL DataBase