在Dot Net前端执行程序的更好方法 [英] Better approach to execute procedure at Dot Net front end

查看:76
本文介绍了在Dot Net前端执行程序的更好方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用C#.Net构建的表单,它有大约40个控件,所有控件数据值都来自Sql server数据库。

以下哪个是更好的方法

1.编写一个过程并为过程中的每个控件添加所有查询,以便它们按顺序执行并将结果作为数据集获取,最后循环控制并与每个数据表绑定。



例如:



connection.Open

DataSet ds = ExecuteProc(SomeProc)

control1.DataSource = ds.Tables(0)

control2.DataSource = ds.Tables(1)

control3.DataSource = ds.Tables(2)









connection.Close



2.为每个控件编写程序并绑定它们,但是使用线程技术使它们并行执行,但在这种情况下,我们需要为每个程序打开和关闭每个程序的连接执行时。



例如:



所有并行运行:



connection.Open

DataSet ds = ExecuteProc( SomeProc1)

control1.DataSource = ds.Tables(0)

connection.Close



连接。打开

DataSet ds = ExecuteProc(SomeProc2)

control2.DataSource = ds.Tables(0)

connection.Close



connection.Open

DataSet ds = ExecuteProc(SomeProc3)

control3.DataSource = ds.Tables( 0)

connection.Close













你能帮助我得到建议方法的答案,还是有其他更好的方法可以更快的速度实现这个目标? />


提前谢谢

解决方案

1.你的第一个方法比第二个更快,因为开放和close连接会消耗一些执行时间,但这种解决方案很难维护。



2. SP执行和获取数据的速度取决于数据库表中的数据量。



3.另一种解决方案是为每个控件使用一个单独的存储过程,如果数据量很大(高于100条记录)则仅使用分页在那些情况下。我有一篇关于在ASP.NET应用程序的上下文中使用分页的文章,我在其中提供SP代码(在数据库级别实现分页)可以被您用作SP的起点。

高级ASPX GridView分页和数据实体 [ ^ ]

I have a form built in C#.Net and it has got approx 40 controls, all the controls datavalues comes from Sql server database.
Which of the following is a better approach
1. Write one procedure and add all the queries for each controls in the procedure so that they execute sequentially and get result as dataset and finally loop controls and bind with each datatable.

For eg:

connection.Open
DataSet ds = ExecuteProc("SomeProc")
control1.DataSource=ds.Tables(0)
control2.DataSource=ds.Tables(1)
control3.DataSource=ds.Tables(2)
.
.
.
.
connection.Close

2. Write procedure for each control and bind them, but with threading technology so that they execute parallel, but in this case for each procedure we need to open and close connections for each procedure when executed.

For e.g:

all running parallel:

connection.Open
DataSet ds = ExecuteProc("SomeProc1")
control1.DataSource=ds.Tables(0)
connection.Close

connection.Open
DataSet ds = ExecuteProc("SomeProc2")
control2.DataSource=ds.Tables(0)
connection.Close

connection.Open
DataSet ds = ExecuteProc("SomeProc3")
control3.DataSource=ds.Tables(0)
connection.Close

.
.
.
.

Can you help me getting the answer for the proposed methods or is there any other better approach to achieve this at faster rate?

Thanks in advance

解决方案

1.Your first approach is faster then the second one, because the open and close connection consume some execution time, but this solution is difficult to maintain.

2.The speed of SP execution and getting the data depends on the amount of data from the database tables.

3. A different solution is to use for each control a separate stored procedure, and if the amount of data are big (higher then 100 records) to use pagination only in those cases. I have an article about using pagination in the context of a ASP.NET application, where I provide a SP code (that implements pagination at the database level) could be used by you as starting point for your SPs.
Advanced ASPX GridView Pagination and Data Entities[^]


这篇关于在Dot Net前端执行程序的更好方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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