DataBinding对手动查询/添加到控件的好处

[英]Benefits of DataBinding over Manually Querying / Adding to Control


I've been a C# programmer for about 2 years total, and professionally for a little more than 1. I work at a company as a developer on an application that began before the days of .NET 2. My question is this:

我已经是一名C#程序员,总共约2年,而且专业性超过1.我作为开发人员在一家公司工作,开始于.NET 2之前的应用程序。我的问题是:

What is the benefit to use databinding from sql queries directly to a control over querying and manually adding items to the control? Is this approach generally considered cleaner, and simpler in terms of deploying? Will there still be cases where manually adding would give more fine grained control over the display / value of the data?

从sql查询直接使用数据绑定到控件查询和手动向控件添加项目有什么好处?这种方法通常被认为是更清洁,在部署方面更简单吗?是否仍会出现手动添加会对数据的显示/值进行更精细控制的情况?

I'm asking because I've been assigned some bugs that deal with some controls that populate themselves based off query results, and would love to clean up unnecessary logic and push that off to the libraries to handle instead of me.

我问的是因为我已经分配了一些错误来处理一些根据查询结果填充自己的控件,并且希望清理不必要的逻辑并将其推送到库来处理而不是我。

Note: We are using .NET 2.0

注意:我们使用的是.NET 2.0

5 个解决方案

#1


5  

I personally find that using the

我个人觉得使用了

control.DataSource = YourSource;
control.DataBind();

process is much easier, you don't have to do the iteration, and overall reduces LOC.

过程要容易得多,您不必进行迭代,总体上减少了LOC。

If working with DropDownLists and other controls you will most likely set the DataValueField and DataTextField properties as well.

如果使用DropDownLists和其他控件,您很可能也会设置DataValueField和DataTextField属性。

#2


1  

Data binding is much easier to set up, less error prone overall, reduces LOC significantly (as Mitchel Sellers said), and, a few minor glitches aside, works fairly reliably.

数据绑定更容易设置,总体上更不容易出错,显着降低LOC(如Mitchel Sellers所说),并且除了一些小故障外,工作相当可靠。

In my experience, you only actually need full manual control if you need to specify the exact update order or timing for data bound controls.

根据我的经验,如果您需要指定数据绑定控件的确切更新顺序或时间,则实际上只需要完全手动控制。

#3


1  

Information joining is much simpler to set up, less problem subject overall, lowers LOC considerably, and, a few modest mistakes aside, will work pretty easily. In my experience, you only actually need full guide control if you need to specify the actual up-date order or time for details certain handles.

信息加入设置起来要简单得多,整体问题主题较少,大大降低了LOC,而且除了一些适度的错误之外,它们的工作非常简单。根据我的经验,如果您需要指定实际的最新订单或时间以获取特定句柄的详细信息,您实际上只需要完整的指南控制。

#4


0  

It can be useful to manually bind if you've got a complex input scenario. With databound input controls you can find that you only know you've got bad data when it hits the DB and throws an exception (badly formatted date/time, integer out of correct range etc).

如果您有复杂的输入方案,手动绑定会很有用。使用数据绑定输入控件,您可以发现只有在遇到数据库并且抛出异常(格式错误的日期/时间,整数超出正确范围等)时才知道您有错误的数据。

You can obviously handle this with the various validation / pre-commit events on the data controls but it can be easier (and more obviously readable) to just manually validate your input and post it when you know it's correct.

您可以使用数据控件上的各种验证/预提交事件来处理这一点,但只需手动验证您的输入并在您知道它正确时发布它就可以更容易(并且更明显可读)。

That's the only reason I can think of and it's only applicable for input. If you're in a read-only scenario then databinding is a no-brainer.

这是我能想到的唯一原因,它只适用于输入。如果您处于只读方案中,则数据绑定是一个明智的选择。

#5


0  

My experiences were quite the opposite to my previous posters here. This blog entry (dated 2006) summarizes my feelings about databinding.

我的经历与我此前的海报完全相反。这篇博客文章(日期为2006年)总结了我对数据绑定的感受。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2008/10/30/7207047e711fad04651b8ed330b12172.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告