Board index » delphi » Reopening/changing DB at runtime
Brigitte Spatz
![]() Delphi Developer |
Reopening/changing DB at runtime2003-10-21 11:27:55 PM delphi140 I want to provide for the user changing their active database at runtime. The code first closes the active database then displays the initial screen where the user can select another (or the same) database and a passwort (if applicable). Then the databse is being opened (and I know it IS open since I can query any field's contents or any table's recordcount) but I get no display in any of my DB components (DBGrid, DBEdit etc.). Using D7 with Access 2000 backend. Here are the relevant parts of various methods: Closing database: grdTablePerson1024.DataController.DataSource := nil; //disconnects grid (I'm using DevExpress' QuantumGrid but have tried with ordinary DBGrid to no avail, and there are also ordinary components like DBEdit etc. that too don't display anything) ... Similar code as above for the other grids for i := 0 to frmDM.ComponentCount - 1 do begin if frmDM.Components[i] is TADOTable then with TADOTable(frmDM.Components[i]) do begin DisableControls; Close; end; if frmDM.Components[i] is TADOQuery then with TADOQuery(frmDM.Components[i]) do begin DisableControls; Close; end; if frmDM.Components[i] is TDataSource then with TDAtaSource(frmDM.Components[i]) do begin DataSet.DisableControls; Enabled := false; end; end; Now the user selects another (or the same) database. Open database: with frmDM do begin if ADOConn.Connected then ADOConn.Connected := false; ADOConn.ConnectionString := strDataSource; ADOConn.Connected := true; end; if frmDM.Components[i] is TADOTable then with TADOTable(frmDM.Components[i]) do begin Open; EnableControls; end; if frmDM.Components[i] is TDataSource then with TDataSource(frmDM.Components[i]) do begin Enabled := true; DataSet.EnableControls; end; //the following is from a separate function that is called for each prepared TADOQuery - Query is the parameter with Query do begin Active := true; EnableControls; end; //end of procedure if grdTablePerson1024.DataController.DataSource = nil then //connects grid grdTablePerson1024.DataController.DataSource := frmDM.dsrPerson; ... Similar code for the other grids I've also tried it with Refresh but again that didn't change anything. Any ideas? TIA. Brigitte |