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
Vijaya KadiyalaPosted Apr 14, 2009, 2:07 PM
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
Jan MontanoPosted Apr 13, 2009, 3:40 AM
Niradhip ChakrabortyPosted Apr 11, 2009, 12:44 PM
MelissaPosted Apr 11, 2009, 6:39 AM
string insertQuery = "INSERT INTO ntxy1 values (" + n + "," + t + "," + x + "," + y + ", '" + dataSetName + "');";