开发者

Using a single DataSource on Multiple .NET Forms

开发者 https://www.devze.com 2023-01-16 15:48 出处:网络
My program has two forms which get data from the same data source.开发者_如何学C After binding controls to tables and fields on both forms, I noticed each form has it\'s own apparently duplicate Data

My program has two forms which get data from the same data source.开发者_如何学C

After binding controls to tables and fields on both forms, I noticed each form has it's own apparently duplicate DataSet.

Is it standard practice for each form to have its own DataSet even though they use the same ConnectionString and connect to the same database at the same time?


The dataset each form uses will be its own instance, to have each form using the same instance you would need to place you data behind a singleton, and bind the forms to the appropriate properties in the Singleton.

As for your question, his behaviour is fairly standard practice on the framework, unless told otherwise the framework will create new instances of entities, and should those entities perform actions such as loading data from a database, will execute those queries independantly for each instance.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号