I'm trying to insert data into my SQL Server 2014 database, but I get an error
Incorrect syntax near ')'.
My table matches the types of data I put in, for example, I'm put an int into a int.
Here is my code:
string ip = Request.UserHostAddress;
string name = "Jesus said: Love your Enemies (V.S.)";
int blueq = Convert.ToInt32(TextBox1.Text);
int redq = Convert.ToInt32(TextBox2.Text);
int whiteq = Convert.ToInt32(TextBox3.Text);
int blackq = Convert.ToInt32(TextBox4.Text);
int whiteqr = Convert.ToInt32(TextBox9.Text);
int redqr = Convert.ToInt32(TextBox10.Text);
int sn = 600;
int price = total_jslye;
string size;
if (RadioButton1.Checked == false)
{
size = "11x35";
}
else
size = "18x50";
try
{
string conn = System.Configuration.ConfigurationManager.ConnectionStrings["SQLCS"].ConnectionString;
var cmd = "INSERT INTO cartsigns (@SignNumber, @redquantity, @bluequantity, @whitequantity, @blackquantity, @whitereflectivequantity, @redreflectivequantity, @size, @SignName, @ipaddress, @price)";
using (SqlConnection com = new SqlConnection(conn))
{
using (SqlCommand cmds = new SqlCommand(cmd, com))
{
cmds.Parameters.AddWithValue("@SignNumber", sn);
cmds.Parameters.AddWithValue("@redquantity", redq);
cmds.Parameters.AddWithValue("@bluequantity", blueq);
cmds.Parameters.AddWithValue("@whitequantity", whiteq);
cmds.Parameters.AddWithValue("@blackquantity", blackq);
cmds.Parameters.AddWithValue("@whitereflectivequantity", whiteqr);
cmds.Parameters.AddWithValue("@redreflectivequantity", redqr);
cmds.Parameters.AddWithValue("@size", size);
cmds.Parameters.AddWithValue("@SignName", name);
cmds.Parameters.AddWithValue("@ipaddress", ip);
cmds.Parameters.AddWithValue("@price", price);
com.Open();
cmds.ExecuteNonQuery();
}
}
}
So please help, thanks
int, and as a result it threw a "throw-away error message" (which actually makes no sense at all). Compilers do such things all the time. I can spot the syntax-error from here. . .