Autor Beitrag
Ace87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Di 26.09.06 09:22 
Wie kann ich 2 Felder (Name und Vorname) aus der Datenbank auslesen lassen und nebeneinander in eine Combobox einfügen??

zum Hintergrund
habe eine Tabelle mit dein spalten ID(Primärschlüssel), Name, Vorname und ect.

ich will das der Name und Vorname in der Combobox nebeneinander steht


Mit freundlichen Grüßen

David
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 26.09.06 09:44 
HI!

Kommt drauf an was für Komponenten du verwendest!
Ich geh mal davon aus das du n TQuery-Objekt verwendest und n DBgrid

ausblenden SQL-Anweisung
1:
2:
 query1.sql.text:= 'Select Name, Vorname from meineTabelle order by Name';
 query1.open;


und dann..

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var i: integer;
...
 for i:= 1 to dbgrid1.datasource.dataset.recordcount do
 begin
  meinComboBox.items.add(dbgrid1.fields[0].asstring + ', ' + dbgrid1.fields[1].asstring);
  dbgrid1.datasource.dataset.recordcount;
 end;


und schon hast du deinen Personen im Format "Name, Vorname" nach Namen sortiert in der ComboBox.

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Di 26.09.06 10:08 
also habe 3 Name und vornamen gerade in meiner Tabelle
aber es wird nur 3 mal der 3te in die Combobox geschrieben
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 26.09.06 10:18 
was für komponenten verwendest du?
wie sieht dein statement aus?

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Di 26.09.06 10:24 
Benutze das normale DBGrid und die normale Combobox aus Delphi 5
ich lass mir alles aus der Tabelle anzeigen

ausblenden SQL-Anweisung
1:
select * from T_Bewerber					


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
procedure TForm5.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  for i:= 1 to dbgrid1.datasource.dataset.recordcount do
  begin
    ComboBox1.items.add(dbgrid1.fields[1].asstring + ', ' + dbgrid1.fields[2].asstring);
    dbgrid1.datasource.dataset.recordcount;
  end;
end;

genau wie du nur das ich sie nicht sortieren lasse
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Di 26.09.06 10:32 
wah sorry!!!
mein Fehler!!!

in der schleife statt
ausblenden Delphi-Quelltext
1:
2:
3:
4:
 .recordcount 
 //muss
 .moveby(1);
 //hin!!!


also so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
var i: Integer;
begin
  for i:= 1 to dbgrid1.datasource.dataset.recordcount do
  begin
    ComboBox1.items.add(dbgrid1.fields[1].asstring + ', ' + dbgrid1.fields[2].asstring);
    dbgrid1.datasource.dataset.moveby(1);
  end;
end;


Sorry!!!

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
Ace87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33

Win XP Home, Linux Suse
Delphi 5, C++ Builder 5, Turbo C#
BeitragVerfasst: Di 26.09.06 10:37 
musst dich doch nicht entschuldigen
ich muss mich bedanken funktioniert super
vielen dank^^
hansa
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3079
Erhaltene Danke: 9



BeitragVerfasst: Di 26.09.06 12:11 
Lass das doch direkt die DB machen :

ausblenden SQL-Anweisung
1:
SELECT VORNAME||', '||NACHNAME AS NAME_OUT					


Spendiere der Combobox ein kleines Dataset und schreibe ins SelectSQL diese eine Zeile rein und fertig.

_________________
Gruß
Hansa
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Di 26.09.06 12:54 
Hallo,

warum der Umweg über das DBGrid?

Hier eine kleine Alternatife um die Daten aus dem Query in das Combobox Feld zu bekommen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
query1.sql.text:= 'Select Name, Vorname from meineTabelle order by Name';
query1.open;
while not query1.eof do begin
  meinComboBox.items.add(query1.FieldByName('Vorname').AsString + ' ' + query1.FieldByName('Nachname').AsString);
  query1.Next;
end;


Das Funktioniert natütlich auch, wenn du die Felder von der Datenbank vereinen lässt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
query1.sql.text:= 'SELECT VORNAME||''||NACHNAME AS NAME_OUT';
query1.open;
while not query1.eof do begin
  meinComboBox.items.add(query1.FieldByName('NAME_OUT').AsString);
  query1.Next;
end;


Gruß
Klabautermann