Autor Beitrag
Der Schreckliche
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48

Windows 7
Delphi XE5
BeitragVerfasst: Mi 22.03.06 15:07 
Hallo, ich möchte einen Filter bei einer ADOQuery setzten.
Die Filterbedingung soll aus einem Editfeld geholt werden.
Die Filterbedingung soll in Jokerzeichen gesetzt sein.
Soweit habe ich es schon herausgefunden, dass die Joker bei SQL '%' sind und nicht '*'.

Das ganze hatte ich mir so ähnlich gedacht

ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADOQuery1.SQL.Text:='Select * from Extremblablah';
ADOQuery1.Filter:='Artikel like %(Edit1.Text)%;
ADOQuery1.Filtered:=true;
ADOQuery1.Open;


Freue mich auf eure Vorschläge!

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Alpha_Wolf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 297

Ubuntu, Win XP, Win Vista
C#, Delphi 6 Prof, Delphi 2007 Prof, Java
BeitragVerfasst: Mi 22.03.06 15:13 
ausblenden Delphi-Quelltext
1:
  ADOQuery1.Filter:= Format('Artikel like %%s%', [QuotedStr(Edit1.Text)]);					


%s steht für den nachfolgenden String (Edit1.Text).


Oder einfacher:

ausblenden Delphi-Quelltext
1:
  ADOQuery1.Filter:= 'Artikel like %' + QuotedStr(Edit1.Text) + '%';					


Achtung ungetestet ;)

EDIT: Oder so wie es das nachfolgende Post beschreibt..

_________________
Diskutiere nie mit einem Irren - er zieht dich auf sein Niveau und schlägt dich mit seiner Erfahrung.


Zuletzt bearbeitet von Alpha_Wolf am Mi 22.03.06 15:16, insgesamt 3-mal bearbeitet
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 22.03.06 15:14 
Abfragestring so anpassen:
ADOQuery1.SQL.Text:='Select * from Extremblablah where Artikel like %'+Edit1.Text+'%'; wenn Artikel ein String ist muß der ganze Ausdruck noch gequoted werden, in diesem Fall muß es ADOQuery1.SQL.Text:='Select * from Extremblablah where Artikel like %'+QuotedStr(Edit1.Text)+'%'; heißen.

_________________
Markus Kinzler.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 22.03.06 15:19 
user profile iconmkinzler hat folgendes geschrieben:
Abfragestring so anpassen:...

ADOQuery1.SQL.Text:='Select * from Extremblablah where Artikel like ''%+Edit1.Text+%''';
bzw.
ADOQuery1.SQL.Text:='Select * from Extremblablah where Artikel like %'+QuotedStr('%'+Edit1.Text+'%');
Sollten die Jokerzeichen nicht IM String sein?

_________________
Na denn, dann. Bis dann, denn.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 22.03.06 15:20 
Sorry, natürlich

_________________
Markus Kinzler.
Der Schreckliche Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48

Windows 7
Delphi XE5
BeitragVerfasst: Mi 22.03.06 16:16 
Also ich habe jetzt sämtliche Vorschläge von euch getestet.
Fragt mich nicht warum aber den Abfragestring mag er überhaupt nicht.
Ist mir schon früher aufgefallen das ich kein where im Abfragestring eingegeben kann.
Da ist mit Delphi böse.

Ich habe jetzt es bisjetzt so gelöst.

ADOQuery1.Filter:='Artikel like %' +QuotedStr(Edit2.Text)+ '%';

Er bringt mir immerhin schon mal eine leere Tabelle, dass ist mehr als meine bisherigen Abbrüche!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 22.03.06 16:27 
ausblenden Delphi-Quelltext
1:
ADOQuery1.SQL.Text:='Select * from Extremblablah where Artikel like ''%'+Edit1.Text+'%''';					

Das % muss natürlich auch innerhalb der Quotes sein.
Der Schreckliche Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 48

Windows 7
Delphi XE5
BeitragVerfasst: Mi 22.03.06 16:40 
Ja Danke, dass war die Richtige Antwort!

Klappt jetzt so wie ich es wollte!