问题
Why it is recommended to process a sql-query in Delphi in the following way?:
dataset.close(); // ?????
dataset.sql.clear(); // old sql-query gets deleted
dataset.sql.add('your sql-query'); // here a query-String is added to your sql-object
dataset.open(); // here your sql-query starts to work
Can it be that closing of a sql-Object defines everytime a default state by which the former dataset resulting from the former sql-query is deleted?
回答1:
When you open a dataset, it enables an active connection, assuming your database/drivers support this. Some database connections are keep-alive, others aren't. For the ones which are, the Open procedure enables an open connection with the database, in which case you can dynamically edit that data using the dataset. So when you Close a dataset, this is typically closing what was opened. Keep in mind that the TDataset is inherited into other more specific types, and the Open / Close procedures are required for many of those.
Closing a dataset also invalidates the data contained within it, therefore is no longer providing that data as well. Your query will stay there, but the data will no longer be available to read/write.
来源:https://stackoverflow.com/questions/25194398/what-is-the-exact-effect-of-tdataset-close-in-delphi