在tableadapter,constructor或load事件中应在哪里填充? [英] Where should i make fill on tableadapter?constructor?or in the load event?

查看:60
本文介绍了在tableadapter,constructor或load事件中应在哪里填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我正在开发一个应用程序,其中我使用数据集和tableadapter与数据库进行连接.
我的问题是建议在表格适配器上填满什么地方?
例如:
this.tableAdapter(this.dataset.table)
在哪里?在InitializeComponent()之后的构造函数中还是在窗体的Load事件中?
谢谢.

Hy, i''m working on a application where i use dataset and tableadapter for the connection with my database.
My question is where it is recomended to make fill on the table adapter?
for example:
this.tableAdapter(this.dataset.table)
Where?In the constructor after InitializeComponent()?or in the Load event of the form?
Thank you.

推荐答案

在此处阅读有关ADO.NET的信息,它将对您有所帮助.

看看这些:
MSDN:ADO.NET [ MSDN:使用ADO.NET访问数据 [ ^ ]

C#Station ADO.NET教程 [为初学者使用ADO.NET [
Read about ADO.NET here and it will help you.

Look at these:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

The C# Station ADO.NET Tutorial[^]
Using ADO.NET for beginners[^]

In the constructor after InitializeComponent()?or in the Load event of the form?
When you need it. Generally during load.


Simply whenever you need the data, fill it.当您不打算使用数据时,无需填写.适配器只需调用一些sql查询,然后将结果填充到数据集(如数据集)即可.适配器的优点在于它可以简单地封装和抽象您使用数据读取器手动执行的操作.提供程序特定的适配器可以在特定的数据提供程序上使用,因此数据集不必担心谁是数据提供程序,无论是Sql Server还是MySql.

忘记添加...如果您的数据集包含多个表,请不要使用表适配器(在键入的数据集中).具有已知错误的表适配器.而是使用通用的数据适配器.
Simply whenever you need the data, fill it. No need to fill when you are not going to use the data. Adapter simply call some sql queries and populate the result to a data holder like dataset. The beauty of the adapter is it simply encapsulate and abstract things which you manually do with a data reader. Provider specific adapters are there which work on specific data providers, so that the dataset doesn''t worry about who are the data provider whether Sql server or MySql.

Forgot to add...Don''t use table adapters (in typed dataset) if your dataset holds more than one table. Table adapters having known bugs. Instead use the common dataadapter.


这篇关于在tableadapter,constructor或load事件中应在哪里填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆