Autor Beitrag
HotLaps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 18.12.02 11:53 
Hallo!

Ich arbeite mit Delphi 7 und einer Oracle 8.1.7 Datenbank.

Ich würde gerne aus Delphi heraus eine SQL Abfrage starten die mir genau einen Datensatz zurückliefert (besteht nur aus einer Spalte), und
das was da zurückkommt möchte ich einer Variablen zuweisen.

Funktioniert das, und wenn ja, wie?
lkz633
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 136

WinXP, Suse Linux 8.2 (unter VMWare)
D7 Prof, K3 Prof
BeitragVerfasst: Mi 18.12.02 12:09 
Hi,

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
query.close;
query.sql.clear;
query.sql.text('select spaltenname from tabelle where spaltenname= ???);
query.open;

query.first;

label1.caption:= query.fieldbyname(spaltenname).asfieldtype;


Hoffe das hilft
Gruss lkz633

Edit: Ich war schneller :D


Zuletzt bearbeitet von lkz633 am Mi 18.12.02 12:13, insgesamt 1-mal bearbeitet
Alfons-G
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 307

Win XP Prof, Linux, Win 7
D5 Prof, D7 Architect, D2005 Architect, D2007 Architect
BeitragVerfasst: Mi 18.12.02 12:11 
Das exakte Vorgehen hängt davon ab, ob Du die BDE-Komponenten oder Oracle-spezifische DB-Kompos verwendest, aber im Prinzip ist es bei allen Query-Komponenten gleich. Ich gehe davon aus, dass Du irgendeine Query-Komponente platziert hast:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
strSQL := 'select MeinFeld from MeineTabelle where MeineBedingung = xxxx...';
MeineQuery.SQL.Clear;
MeineQuery.SQL.Add (strSQL);
MeineQuery.Open;
MeineVariable := MeineQuery.Fields[0].AsString;
MeineQuery.Close;
// Alternativ: ... := MeineQuery.FieldByName('MeinFeld').AsString oder natürlich AsInteger, AsFloat, AsDate ...
Du musst natürlich bei der where-Bedingung der Abfrage sicher stellen, dass genau ein Datensatz als Ergebnis zurückkommt.

:idea:

_________________
Alfons Grünewald
HotLaps Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 42



BeitragVerfasst: Mi 18.12.02 12:45 
Vielen Dank!

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
strSQL := 'select MeinFeld from MeineTabelle where MeineBedingung = xxxx...'; 
MeineQuery.SQL.Clear; 
MeineQuery.SQL.Add (strSQL); 
MeineQuery.Open; 
MeineVariable := MeineQuery.Fields[0].AsString; 
MeineQuery.Close;



Hat funktioniert!

Code-Tags aktiviert von Klabautermann