Reputation: 33
Hey this is my code and this is the error I get:
Exception thrown: 'System.Data.SqlClient.SqlException' in System.Data.dll ("Incorrect syntax near ')'.")
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);
}
Upvotes: 2
Views: 1306
Reputation: 39946
You have missed the Values
keyword:
SqlCommand addUser = new SqlCommand("insert into userDetails Values(@empID ," +
^^^^
"@employeeName ,@userName , @userType, @password)", con);
Upvotes: 7