Autor Beitrag
Aadelbert
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Fr 09.11.07 16:56 
Hallo Leute,

die Abfrage sieht im Moment folgendermaßen aus, liefert aber einen "Syntaxfehler (fehlender Operator) ...
ausblenden Delphi-Quelltext
1:
ADODataSet3.CommandText := 'select * from Bestand where Artikel="'+ SuchArtikel +'"'+'and where Datum between '+ 'DATEVALUE'+'("'+Edit1.Text+'")'+'and'+ 'DATEVALUE'+'("'+Edit2.Text+'")'+' ORDER BY lfd';					


Ich habe bisher so eine Abfrage nicht gemacht und brauche mal etwas Hilfe.

Danke Aadelbert

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Fr 09.11.07 17:10 
In der Zeile ist zumindest Delphi-Fehler. Kanns vielleicht sein, dass einfach in der Zeile vorher das Semikolon fehlt?
Oder meinst du einen SQL-Fehler?

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Fr 09.11.07 21:56 
Also, in der Zeile vorher fehlt kein Semikolon.

Kann es vielleicht sein, dass das mit "... where Artikel..." und dann nochmal mit "...where Datum..." nicht geht?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 09.11.07 22:12 
Versuch es mal mit (SQL-)Parametern

_________________
Markus Kinzler.
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Fr 09.11.07 23:06 
Also so komm ich nicht weiter. Ich brauche schon etwas mehr an Hinweisen. Mit der Suche hier im Forum komme ich auch nicht wirklich weiter.

Trotzdem schon mal Danke
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Fr 09.11.07 23:09 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
ADODataSet3.CommandText := 'select * from Bestand where Artikel=:artikel and where Datum between :datum1 and :datum2 ORDER BY lfd'; 
...
ADODataSet3.Params.ParamByName('artikel').asString := SuchArtikel;
...

_________________
Markus Kinzler.
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Fr 09.11.07 23:59 
Danke, der erste Teil funktioniert offensichtlich. Nur so richtig klar komme ich noch nicht damit. Denn jetzt bekomme ich folgenden Hinweis: [Fehler] Unit13.pas(351): Undefinierter Bezeichner: 'Params'. Was muss ich jetzt machen. Tut mir leid, ich tu mich sehr schwer damit. Könntest Du nochmals etwas Hilfe geben?
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 10.11.07 00:01 
ausblenden Delphi-Quelltext
1:
ADODataSet3.Parameters.ParamByName('artikel').asString := SuchArtikel;					

_________________
Markus Kinzler.
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Sa 10.11.07 00:10 
Es hakt immer noch: [Fehler] Unit13.pas(351): Undefinierter Bezeichner: 'asString'.
Mir kommt der Kaffee so langsam hoch! Wieso raff ich das nicht? Ik seh nischt mehr, sitz schon den ganzen Tag am Rechner.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Sa 10.11.07 00:12 
Versuchs mal mit .Value

_________________
Markus Kinzler.
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: Sa 10.11.07 00:18 
Value klappt zwar, aber trotzdem erhalte ich noch eine Exception: Ein Parameterobjekt ist nicht ordnungsgemäß definiert. Inkonsistente oder unvollständige Informationen wurden angegeben. ...

Ich fühls, die Lösung ist nahe!!!
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: So 11.11.07 11:59 
Leider funktioniert es immer noch nicht und ich bin auf Hilfe von Wissenden angewiesen.
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: So 11.11.07 13:52 
Wenn schon, dann so :

ausblenden Delphi-Quelltext
1:
2:
ADODataSet3.ParamByName('artikel').asString := SuchArtikel;
...

_________________
Gruß
Hansa
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: So 11.11.07 15:38 
ADODataSet3.ParamByName(' artikel ').asString := SuchArtikel;
Wenn ich das so eingebe kann ich nicht compilieren:
[Fehler] Unit13.pas(353): Undefinierter Bezeichner: 'ParamByName'

ADODataSet3.Parameters.ParamByName(‘artikel’).asString := SuchArtikel;
Dann kommt das:
[Fehler] Unit13.pas(351): Undefinierter Bezeichner: 'asString'

Das habe ich und lässt sich wenigstens compilieren:
ausblenden Delphi-Quelltext
1:
2:
3:
ADODataSet3.CommandText := 'select * from Bestand where=:artikel and where Datum between : datum1 and : datum2 ORDER BY lfd’;
ADODataSet3.Parameters.ParamByName (‘artikel’).Value := SuchArtikel;
ADODataSet3.Active := True;


Value klappt zwar, aber trotzdem erhalte ich noch eine Exception: Ein Parameterobjekt ist nicht ordnungsgemäß definiert. Inkonsistente oder unvollständige Informationen wurden angegeben. ...

Was ist denn hier noch falsch?
Kann man das mit ADOQuery vielleicht einfacher lösen?

Hilfe!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: So 11.11.07 16:33 
Hallo,

ausblenden Delphi-Quelltext
1:
ADODataSet3.Parameters.ParamByName('artikel').Value := SuchArtikel;					

ist schon ok.
Du verwendest auch die Parameter Datum1 und Datum2. Die mußt Du auch setzen (genau wie artikel)! Und dann noch was: auch wenn ich noch nie was mit ADO gemacht habe, glaub ich aber nicht, daß dein SQL korrekt ist:

ausblenden SQL-Anweisung
1:
select * from Bestand where=:artikel and where Datum between : datum1 and : datum2 ORDER BY lfd					

würde ich sagen muß so heißen:
ausblenden SQL-Anweisung
1:
select * from Bestand where Artikel=:artikel and (Datum between :datum1 and :datum2) ORDER BY lfd					

(Artikel eventuell noch quoten, je nachdem ob es eine Zahl oder ein String ist)

Grüße,
Uli
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: So 11.11.07 16:42 
@uko: Die Abfrage sollte so stimmen, das 2. and gehört ja zum between. Bei Parametern brauchst man nicht Quoten, das ist ja gerade einer der Vorteile von Parametern.
@Aadelbert: Anscheinend kann ADO aber Probleme mit der Bestimmung des Typs des Parameters. Setze mal seinen Typ

_________________
Markus Kinzler.
Robert.Wachtel
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 895
Erhaltene Danke: 7

Windows 7 Ultimate x64
D5 Ent, D7 Arch, RAD Studio 2010 Pro, VS 2008
BeitragVerfasst: So 11.11.07 16:56 
Ich vermisse die Zuweisung der Parameter datum1 und datum2...

// Edit: Gerade erst gesehen, dass uko das auch schon erwähnt hat, also vergesst diesen Beitrag einfach... :mrgreen:
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: So 11.11.07 19:15 
@uko: Ich habe jetzt den Code so angepasst. Jetzt kann ich zwar compilieren und das Programm startet ...

Der Code sieht jetzt so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
ADODataSet3.CommandText := 'select * from Bestand where Artikel=:Artikel and (Datum between :SuchDatum1 and :SuchDatum2) ORDER BY lfd';
ADODataSet3.Parameters.ParamByName(' Artikel ').Value := Such Artikel;
ADODataSet3.Active := True;


... aber es werden keine Daten angezeigt.

Moderiert von user profile iconmatze: Delphi-Tags hinzugefügt
uko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 220
Erhaltene Danke: 1

Win XP, VISTA, WIndows 7
Delphi 2007/2010 Prof
BeitragVerfasst: So 11.11.07 23:05 
Hast Du denn die Werte für die Parameter SuchDatum1 und Suchdatum2 gesetzt? Das taucht in deinem Code nämlich nicht auf.

Grüße,
Uli
Aadelbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 90

XP, WIN 2000, NT 4.0
D6 Enterprise
BeitragVerfasst: So 11.11.07 23:52 
Meine Güte, ich blick es einfach nicht! Wo und wie muss ich die setzen?

Ich danke euch allen für die Geduld!