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!
Loading

Melissa3 reputationPosted Apr 11, 2009, 2:39 AM EDT
string insertQuery = "INSERT INTO ntxy1 values (" + n + "," + t + "," + x + "," + y + ", '" + dataSetName + "');";
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Apr 11, 2009, 8:44 AM EDT
Jan MontanoRank #1,295 · 1.3K reputationPosted Apr 12, 2009, 11:40 PM EDT
Vijaya KadiyalaRank #1,085 · 1.8K reputationPosted Apr 14, 2009, 10:07 AM EDT
This is not the best way to do.
always use StringBuilder to construct the string. This makes life easy in doinf Debug.
Thanks -- Vijaya Kadiyala
www.DotNetVJ.com