我无法找到的错误在我的代码发现错误,我无法找到它帮我出
Error: System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near 'Name'.
try
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserData_DB"].ConnectionString);
string insert = "INSERT INTO UserData(First Name,Last Name,Father Name,CNIC NO,Gender,Religion,Address,City, Cell Number, Email) VALUES (@fName,@lName,@fathName,@cnicNo,@gender,@religion,@address,@city,@cellNumber,@email)";
SqlCommand com = new SqlCommand(insert, con);
com.Parameters.AddWithValue("@fName", TextBoxfName.Text);
com.Parameters.AddWithValue("@lName", TextBoxlName.Text);
com.Parameters.AddWithValue("@fathName", TextBoxFatherName.Text);
com.Parameters.AddWithValue("@cnicNo", TextBoxcnicNo.Text);
com.Parameters.AddWithValue("@gender", RadioButtonList1.SelectedItem.Value.ToString());
com.Parameters.AddWithValue("@religion", RadioButtonList2.SelectedItem.Value.ToString());
com.Parameters.AddWithValue("@address", TextBoxAddress.Text);
com.Parameters.AddWithValue("@city", DropDownList1.SelectedValue.ToString());
com.Parameters.AddWithValue("@cellNumber", TextBoxCellNumber.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write("Error: " + ex.ToString());
}
列名不能包含空格!如果你的列中有空格(开头真的是个坏主意),你必须在它们周围使用**方括号:INSERT INTO UserData([First Name],[Last Name],[Father Name])。 ....' –
在sql中的列不应该用两个单词来命名,所以它的first_name或firstName或类似的东西。 – thsorens