Recent

Author Topic: [SOLVED] SQLite open database with OpenDialog  (Read 199 times)

Pe3s

  • Sr. Member
  • ****
  • Posts: 335
[SOLVED] SQLite open database with OpenDialog
« on: November 27, 2022, 09:54:42 pm »
Hello, I noticed that when I open one database and want to open another, it does not open. What do I need to fix for the code to work properly?
Code: Pascal  [Select][+][-]
  1. procedure TfGlowna.SpeedButton2Click(Sender: TObject);
  2. begin
  3.   if not OpenDialog1.Execute then Exit;
  4.  
  5.   ZConnection1.Database:= OpenDialog1.FileName;
  6.   ZConnection1.Connected:= True;
  7.  
  8.   ZQuery1.close;
  9.   ZQuery1.SQL.Clear;
  10.   ZQuery1.SQL.Text:= 'SELECT * FROM product';
  11.   ZQuery1.Open;
  12. end;
  13.  
« Last Edit: November 28, 2022, 04:53:26 pm by Pe3s »

dseligo

  • Hero Member
  • *****
  • Posts: 901
Re: SQLite open database with OpenDialog
« Reply #1 on: November 28, 2022, 12:33:26 am »
Just disconnect from database before changing database name. In line 4 add:
Code: Pascal  [Select][+][-]
  1. ZConnection1.Disconnect; // or ZConnection1.Connected := False;

Pe3s

  • Sr. Member
  • ****
  • Posts: 335
Re: SQLite open database with OpenDialog
« Reply #2 on: November 28, 2022, 04:53:04 pm »
@dseligo Thank you :)

 

TinyPortal © 2005-2018