Kindly help me on identifying the cause of this error
Incorrect syntax near the keyword 'JOIN'
Here is the code:
Label name = (Label)GuitarBrandsGridView.Rows[e.RowIndex].FindControl("lblName"); string queryGuitarItems = "DELETE FROM stringInstrumentItem JOIN brand ON stringInstrumentItem.brandId = brand.brandId WHERE stringInstrumentItem.brandId IN(SELECT brand.brandId FROM brand WHERE name = @brand)"; using (SqlConnection connectionGuitarItems = new SqlConnection(ConfigurationManager.ConnectionStrings["musicStoreConnection"].ToString())) { using (SqlCommand commandGuitarItems = new SqlCommand(queryGuitarItems, connectionGuitarItems)) { connectionGuitarItems.Open(); commandGuitarItems.Connection = connectionGuitarItems; commandGuitarItems.Parameters.Add(new SqlParameter("@brand", name.Text)); commandGuitarItems.ExecuteNonQuery(); connectionGuitarItems.Close(); commandGuitarItems.Parameters.Clear(); } }
DELETE FROM stringInstrumentItem JOIN brand ON stringInstrumentItem.brandId = brand.brandId WHERE stringInstrumentItem.brandId IN(SELECT brand.brandId FROM brand WHERE name = 'brand value here')you will see the same error. You need to get that query working in Management Studio, and then try and use it in your app. The issue is a SQL issue - not C# or ASP.NET .SELECT *instead of aDELETE:DELETE FROM stringInstrumentItem s JOIN brand b ON s.brandId = b.brandId WHERE b.name = @brand