The best way Counting Records In ASP.NET 2.0

2 Nov

Project requirements:
The project look for data from 20 tables with 1000 records of 5 different categories.

This article provide a possible solution:

Imports System.Data
Imports System.Data.SQLClient

Partial Class index
Inherits System.Web.UI.Page

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
Dim objCon As New SqlConnection(“server=server;User id=userid;password=password;database=databasename“)

Dim cmd As SqlCommand = New SqlCommand(“Select count(*) from ptg_hotels”, objCon)
End Sub
End Class

It’s worry a little the amounts of calls to the database and the impact that may imply in performance.

Approach 1:
Make the above call to the database 100 times.
Approach 2:
Create a view in the database that contain all required values
Approach 3:
Create something as batch/cron that calculate all that values and insert it in a table may be 2 times a day because its not required that values of the counting be updated all time.
Approach 4:
Receive the values from Stored Procedure; this may be gain a little performance v’s client based counting

Lets see in the next two days what’s the approach finally used.





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: