jeudi 7 juillet 2016

Problems with SQL delete statement

I'm getting an error stating that I need a second argument in my remove command, but I believe I already have two in here. I'm pretty new to SQL and C# so maybe I'm not understanding it correctly.

private void RemoveFromRecipeButton_Click(object sender, EventArgs e)
{
    string query = "DELETE FROM RecipeIngredient WHERE Id = @RecipeId & @IngredientId";

    using (connection = new SqlConnection(connectionstring))
    using (SqlCommand command = new SqlCommand(query, connection))
    {
        connection.Open();

        command.Parameters.Remove("@RecipeId", ListRecipes.SelectedValue);
        command.Parameters.Remove("@IngredientId", ListAllIngredients.SelectedValue);

        command.ExecuteScalar();
    }

    PopulateRecipes();
}

I'm thinking it might be because I put both RecipeID and IngredientID in the same line with an &, but that works on my add statement.

So I'm really unsure of how remove should work. Can anyone assist in identifying the issue?

Aucun commentaire:

Enregistrer un commentaire