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)
-   -   conexion sqlite con mi aplicación (https://www.clubdelphi.com/foros/showthread.php?t=82667)

jonydread 01-04-2013 02:12:08

conexion sqlite con mi aplicación
 
amigos, estoy en un dilema es primera vez que hago esto de bd y he averiguado pero me estanque

tengo la sgte app muy sencilla y quiero usar sqllite y se almacenen datos agregados a mi listview me explico,
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
var
 nItem: TListItem;
begin
  nItem := ListView1.Items.Add;
  nItem.Caption := DateToStr(DateTimePicker1.Date);
  nItem.SubItems.Add(ComboboxEx1.Text);
  nItem.SubItems.Add(edit1.Text);
  nItem.SubItems.Add(edit2.Text);
end;

tengo delphi 2010 embarcadero y sqlliteexpert personal y uso windows 7
cree una tabla y datos esto aparece en el apartado dll de sqllite expert y el archivo que guarda es de extension .db
Código SQL [-]
CREATE TABLE "Datos" (
  [fecha] DATETIME, 
  [area] CHAR, 
  [tipo] CHAR, 
  [detalle] CHAR);
ahora mi problema no se como hacer que esto funcione xD
he visto sobre conectar con ADO pero no se los parametros que debo colocar
y en DBexpress al parecer es mas simple pero tampoco se como hacerlo
si me pudieran dar un ejemplo de como realizar esto como agrego los datos a la BD seria de mucha ayuda


saludos y muchas gracias!!^\||/

jonydread 02-04-2013 06:06:17

amigos estoy usando sqlite wrapper de itwriting tengo esto
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
var
 nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
id1,id2,id3,id4: String;
begin
  nItem := ListView1.Items.Add;
  nItem.Caption := DateToStr(DateTimePicker1.Date);
  id1 := DateToStr(DateTimePicker1.Date);
  nItem.SubItems.Add(ComboboxEx1.Text);
  id2 := ComboboxEx1.Text;
  nItem.SubItems.Add(edit1.Text);
  id3 := edit1.Text;
  nItem.SubItems.Add(edit2.Text);
  id4 := edit2.Text;
  begin
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
//begin a transaction
sldb.BeginTransaction;
//do the insert
sSQL := 'INSERT INTO Datos VALUES ("id1",id2,"id3","id4");';
sldb.ExecSQL(sSQL);
//end the transaction
sldb.Commit;
end

end;

pero al recuperar asi los valores "id1",id2,"id3","id4" sale error como logro recuperar los datos??

olbeup 02-04-2013 09:12:52

Cita:

Empezado por jonydread (Mensaje 457934)
amigos estoy usando sqlite wrapper de itwriting tengo esto
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
var
 nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
id1,id2,id3,id4: String;
begin
  nItem := ListView1.Items.Add;
  nItem.Caption := DateToStr(DateTimePicker1.Date);
  id1 := DateToStr(DateTimePicker1.Date);
  nItem.SubItems.Add(ComboboxEx1.Text);
  id2 := ComboboxEx1.Text;
  nItem.SubItems.Add(edit1.Text);
  id3 := edit1.Text;
  nItem.SubItems.Add(edit2.Text);
  id4 := edit2.Text;
  begin <--- Este te sobra.
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
//begin a transaction
sldb.BeginTransaction;
//do the insert
sSQL := 'INSERT INTO Datos VALUES ("id1",id2,"id3","id4");';
sldb.ExecSQL(sSQL);
//end the transaction
sldb.Commit;
end

end;

pero al recuperar asi los valores "id1",id2,"id3","id4" sale error como logro recuperar los datos??

Hay un begin que te sobra.

Un saludo

jonydread 03-04-2013 03:16:07

ahora me dice No such column n1
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
var
 nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
n1,n2,n3,n4: String;
begin
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
  nItem := ListView1.Items.Add;
  nItem.Caption := DateToStr(DateTimePicker1.Date);
  n1 := DateToStr(DateTimePicker1.Date);
  nItem.SubItems.Add(ComboboxEx1.Text);
  n2 := ComboboxEx1.Text;
  nItem.SubItems.Add(edit1.Text);
  n3 := edit1.Text;
  nItem.SubItems.Add(edit2.Text);
  n4 := edit2.Text;
//begin a transaction
sldb.BeginTransaction;
//do the insert
sSQL := 'INSERT INTO Datos VALUES (n1,n2,n3,n4);';
sldb.ExecSQL(sSQL);
//end the transaction
sldb.Commit;
end;

saludos

jonydread 03-04-2013 05:25:54

me respondo y ha funcionado por lo tanto dejo un codigo funcional si sirve a alguien
Código Delphi [-]
procedure TForm1.BitBtn1Click(Sender: TObject);
var
 nItem: TListItem;
slDBpath: string;
sldb: TSQLiteDatabase;
sltb: TSQLIteTable;
sSQL: String;
id1,id2,id3,id4: String;
begin
  nItem := ListView1.Items.Add;
  nItem.Caption := DateToStr(DateTimePicker1.Date);
  id1 := DateToStr(DateTimePicker1.Date);
  nItem.SubItems.Add(ComboboxEx1.Text);
  id2 := ComboboxEx1.Text;
  nItem.SubItems.Add(edit1.Text);
  id3 := edit1.Text;
  nItem.SubItems.Add(edit2.Text);
  id4 := edit2.Text;
  begin
slDBPath := ExtractFilepath(application.exename)
+ 'bd\dbdatos.db';
sldb := TSQLiteDatabase.Create(slDBPath);
//begin a transaction
sldb.BeginTransaction;
//do the insert
sSQL := 'INSERT INTO Datos VALUES (' +QuotedStr(id1)+',' +QuotedStr(id2)+',' +QuotedStr(id3)+',' +QuotedStr(id4)+');';
sldb.ExecSQL(sSQL);
//end the transaction
sldb.Commit;
end

end;


La franja horaria es GMT +2. Ahora son las 06:27:58.

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