I get
SqlException: incorrect syntax near nvarchar
Incorrect syntax near 'ID'
in my code. Please can somebody help me solve it?
My code is
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlCommand cmd;
SqlConnection con = new SqlConnection(@"Data Source=HAIER-PC;Initial Catalog=PDCS;Integrated Security=True");
SqlDataAdapter SDA;
private void button3_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("INSERT INTO CusUtil(Customer ID, Age, Experience, Preferred Alternatives, Outer Shell, Base Gasket, Vent, Vent Type, Impact Absorbent Liner, Eyeport Gasket, Face Shield, Comfort Liner, Chin Strap, Weight, Estimated Price)
VALUES(@Customer ID, @Age, @Experience, @Preferred Alternatives, @Outer Shell, @Base Gasket, @Vent, @Vent Type, @Impact Absorbent Liner, @Eyeport Gasket, @Face Shield, @Comfort Liner, @Chin Strap, @Weight, @Estimated Price)", con);
cmd.Parameters.Add("@Customer ID", textBox1.Text);
cmd.Parameters.Add("@Age", comboBox1.SelectedItem.ToString());
cmd.Parameters.Add("@Experience", comboBox2.SelectedItem.ToString());
cmd.Parameters.Add("@Preferred Alternatives", comboBox3.SelectedItem.ToString());
cmd.Parameters.Add("@Outer Shell", textBox2.Text);
cmd.Parameters.Add("@Base Gasket", textBox3.Text);
cmd.Parameters.Add("@Vent", textBox4.Text);
cmd.Parameters.Add("@Vent Type", textBox5.Text);
cmd.Parameters.Add("@Impact Absorbent Liner", textBox6.Text);
cmd.Parameters.Add("@Eyeport Gasket", textBox7.Text);
cmd.Parameters.Add("@Face Shield",textBox8.Text);
cmd.Parameters.Add("@Comfort Liner",textBox9.Text);
cmd.Parameters.Add("@Chin Strap",textBox10.Text);
cmd.Parameters.Add("@Weight",textBox11.Text);
cmd.Parameters.Add("@Estimated Price",textBox12.Text);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
The error occurs at ExecuteNonQuery
. The code simply save the data into a SQL Server database.