Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   cargar datos a listview desde bd sqlite (https://www.clubdelphi.com/foros/showthread.php?t=82710)

jonydread 05-04-2013 05:32:20

cargar datos a listview desde bd sqlite
 
amigos ya no encuentro como y requiero de alguna ayuda
estoy trabajando con sqlite y sqilte wrapper para trabajar la bd y quiero cargar los datos a una listview tengo esto
Código Delphi [-]
procedure TForm1.BitBtn2Click(Sender: TObject);
var
nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
i : integer;
 begin
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
//begin a transaction
//end the transaction
sltb := slDb.GetTable('SELECT * FROM Datos');
try

if sltb.Count > 0 then
begin
//display first row
  nItem := ListView1.Items.Add;
  nItem.Caption := sltb.FieldByName['fecha'] ;
  nItem.SubItems.Add(sltb.FieldByName['area']);
  nItem.SubItems.Add(sltb.FieldByName['tipo']);
  nItem.SubItems.Add(sltb.FieldByName['detalle']);
  sltb.Next;

end;
finally
sltb.Free;
end;
 end;

pero solo me agrega el primer registro ya no se que mas hacer
espero su ayuda


saludos!

Chris 05-04-2013 07:10:50

No sé como funcionan exactamente los componentes que estás usando para acceder a SQLite. Pero si son decendientes de TDataset tu código se resolvería así:

Código Delphi [-]
procedure TForm1.BitBtn2Click(Sender: TObject);
var
nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
i : integer;
 begin
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
//begin a transaction
//end the transaction
sltb := slDb.GetTable('SELECT * FROM Datos');
try

if sltb.Count > 0 then
while not sltb.eof do // <-- Abro un bucle que recorre todos los registros.
begin
//display first row
  nItem := ListView1.Items.Add;
  nItem.Caption := sltb.FieldByName['fecha'] ;
  nItem.SubItems.Add(sltb.FieldByName['area']);
  nItem.SubItems.Add(sltb.FieldByName['tipo']);
  nItem.SubItems.Add(sltb.FieldByName['detalle']);
  sltb.Next;

end;
finally
sltb.Free;
end;
 end;

Saludos!

jonydread 06-04-2013 16:04:24

exelente tantas vueltas que me di y hay estaba la solucion muchas gracias!!!


La franja horaria es GMT +2. Ahora son las 23:29:49.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi