Here's the problem:
I'm working with Visual Studio and made a Winforms application. This is supposed to work with a database. Reading the database using a SQL Query works totally fine without any problems.
cmd.CommandText =
"SELECT Buecher.Bu_ISBN AS ISBN,
Buecher.Bu_Titel AS Titel,
Buecher.Bu_Originaltitel AS Originaltitel,
Buecher.Bu_Buchreihe AS Buchreihe,
Buecher.Bu_Genre AS Genre,
Autor.Au_Vorname AS [Autor-Vorname],
Autor.Au_Nachname AS[Autor-Nachname],
Verlag.Ve_Name AS Verlag
FROM ((((Buecher
INNER JOIN [Buch-Autor]
ON Buecher.Bu_ID = [Buch-Autor].Bu_ID)
INNER JOIN Autor
ON [Buch-Autor].Au_ID = Autor.Au_ID)
INNER JOIN [Buch-Verlag]
ON Buecher.Bu_ID = [Buch-Verlag].Bu_ID)
INNER JOIN Verlag
ON [Buch-Verlag].Ve_Name = Verlag.Ve_Name)";
ausgabe();
(it is in German, ausgabe() is a method that transfers the Query into a DataGridView - works fine)
Later in the program the user shall search with various criteria using text boxes, that's where it doesn't work anymore, the Query simply is not executed.
if (optBuch.Checked == true)
{
cmd.CommandText =
"SELECT Buecher.Bu_ISBN AS ISBN,
Buecher.Bu_Titel AS Titel,
Buecher.Bu_Originaltitel AS Originaltitel,
Buecher.Bu_Buchreihe AS Buchreihe,
Buecher.Bu_Genre AS Genre,
Autor.Au_Vorname AS [Autor-Vorname],
Autor.Au_Nachname AS [Autor-Nachname],
Verlag.Ve_Name AS Verlag
FROM ((((Buecher
INNER JOIN [Buch-Autor]
ON Buecher.Bu_ID = [Buch-Autor].Bu_ID)
INNER JOIN Autor
ON [Buch-Autor].Au_ID = Autor.Au_ID)
INNER JOIN [Buch-Verlag]
ON Buecher.Bu_ID = [Buch-Verlag].Bu_ID)
INNER JOIN Verlag
ON [Buch-Verlag].Ve_Name = Verlag.Ve_Name)
WHERE (Buecher.Bu_ISBN = '%" + txtOpt1.Text + "%')
AND (Buecher.Bu_Titel = '%" + txtOpt2.Text + "%')
AND (Buecher.Bu_Originaltitel = '%" + txtOpt3.Text + "%')
AND (Buecher.Bu_Buchreihe = '%" + txtOpt4.Text + "%')
AND (Buecher.Bu_Genre = '%" + txtOpt5.Text + "%')
AND (Autor.Au_Vorname = '%" + txtOpt6.Text + "%')
AND (Autor.Au_Nachname = '%" + txtOpt7.Text + "%')
AND (Verlag.Ve_Name = '%" + txtOpt8.Text + "%')";
I tried various forms of the Query but until now no one worked. It works totally fine when I delete the whole "Where" section...
I hope I could express myself in a comprehensible way.