Marox
Marox

Reputation: 359

SQL Delete with Inner Join ado.net

So I have two tables:

enter image description here

enter image description here

and I want to delete a record from Kategoria-Adres, where the ID_Adres in Kategoria-Adres is the same like ID_Adres in Adres when I select an item from a listbox.

 string delete_string1 = "DELETE FROM Kategoria-Adres INNER JOIN Adres ON
 Kategoria-Adres.ID_Adres = Adres.ID_Adres WHERE Adres.Adres LIKE "
 + listBox1_Selected_Item + " AND Adres.ID_Adres = Kategoria-Adres.ID_Adres";

I've tried this, but it doesn't work for me.

Upvotes: 0

Views: 401

Answers (2)

bilpor
bilpor

Reputation: 3921

Your Like clause is missing the %

Upvotes: 0

Paul
Paul

Reputation: 120

It looks like the problem is in your query.

Something like this should work:

DELETE FROM Kategoria-Adres
INNER JOIN [Adres] ON [Kategoria-Adres].[ID_Adres] = [Adres].[ID_Adres]
WHERE [Adres].[Adres] LIKE '%" + listbox1.SelectedValue + "%' AND [Adres].[ID_Adres] = [Kategoria-Adres].[ID_Adres]

As a side note, you should include your C# and ADO.Net code in the future incase you're missing something from there, and the error code.

Upvotes: 1

Related Questions