What is the exact effect of TDataset.close() in Delphi?

杀马特。学长 韩版系。学妹 提交于 2020-01-07 09:03:31

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!