denissapop denissapop - 4 months ago 39
SQL Question

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

I'm doing a delete for a row in the sql database. But everytime I run the program I receive this error:


An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: Incorrect syntax near ','.


Here are my sql codes:

string strConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);

SqlCommand cmd = new SqlCommand("DELETE FROM Customer, WHERE Password = @pass", myConnect);

cmd.Parameters.Add("@pass", SqlDbType.VarChar);
cmd.Parameters["@pass"].Value = txtPassword.Text;

myConnect.Open();
int result = cmd.ExecuteNonQuery();

if (result > 0)
Response.Redirect("Deleteaccountsummary.aspx");
else
lblDelete.Text = "Delete Fail";
myConnect.Close();


Please advise!

Answer

You have an extra comma, try this:

new SqlCommand("DELETE FROM Customer WHERE Password = @pass", myConnect)