Click here to Skip to main content
15,914,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900