附近的语法不正确

附近的语法不正确

嘿,这是我的代码,这是我得到的错误:


  抛出异常:“ System.Data.SqlClient.SqlException”
  System.Data.dll(“')附近的语法不正确。”)




void addMember()
{
    try
    {
       //con.Open();
        String EmpID = txtEmpID.Text.ToString().Trim();
        String EmployeeName = txtEmpID.Text.ToString().Trim();
        String UserName = txtUsername.Text.ToString().Trim();
        String UserType = cmbUserType.GetItemText(cmbUserType.SelectedItem);
        String PassWord = txtPassword.Text.ToString().Trim();
        SqlCommand addUser = new SqlCommand("insert into  userDetails(@empID ,@employeeName ,@userName , @userType, @password)", con);
        addUser.Parameters.Add(new SqlParameter("@empID", EmpID));
        addUser.Parameters.Add(new SqlParameter("@employeeName", EmployeeName));
        addUser.Parameters.Add(new SqlParameter("@userName", UserName));
        addUser.Parameters.Add(new SqlParameter("@userType", UserType));
        addUser.Parameters.Add(new SqlParameter("@password", PassWord));

        int x = addUser.ExecuteNonQuery();

        if (x > 0)
        {

            MessageBox.Show("Data Inserted", "User Form", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        //con.Close();
    }
    catch (Exception ex)
    {
        MessageBox.Show("" + ex);
    }

最佳答案

您错过了Values关键字:

SqlCommand addUser = new SqlCommand("insert into userDetails Values(@empID ," +
                                                              ^^^^
                                    "@employeeName ,@userName , @userType, @password)", con);

09-13 04:30