Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How to save the DataTable for furhter access with .Net generics

Posted on 2012-08-19
10
Medium Priority
?
258 Views
Last Modified: 2012-09-14
Hi,
Instead of accesing the database multiple times,I am storing the DataTable in ViewState.
DataTable dtSql = (DataTable) ViewState["tblxmlcol"];

On web page left menu links,when the link is clicked I am getting DataTable back from ViewState and accessing the Xml contents column and decoding it to Html.

It is slowing down the process.Is there any way  can I make it faster.
Instead of storing the DataTable in ViewState and converting it to DataTable again can you suggest something using.Net generics or something else.

Thanks,
0
Comment
Question by:KavyaVS
10 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 38309656
Are you binding the Datatable to a Treeview or menu control?

There is no replacement to storing the datatable in ViewState. You have to hit the database if you want to reduce the pagesize.
0
 
LVL 18

Expert Comment

by:Rajar Ahmed
ID: 38309689
Put a sample code here which can reflect your issue for us , so we can suggest any ideas to improve .

Meeran03
0
 
LVL 25

Assisted Solution

by:Rouchie
Rouchie earned 2000 total points
ID: 38310832
To be honest you're probably putting more strain on the server by storing the DataTable in Viewstate rather than just hitting the database.  Because ViewState will increase massively, you're also increasing the bandwidth and slowing things down for the user (don't forget upload speeds are far slower than downloads, so sending posts back to the server will take longer)!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:KavyaVS
ID: 38363637
I am binding the DataTable column to left menu link.

I am stroing the DataTable in ViewState in the Page's original request.
On web page left menu links,when the link is clicked I am getting DataTable back from ViewState.
Instead of accessing the DataBase multiple times,whenever the link from left menu is clicked
I am getting the dataTable back from ViewState.

I have 20 links in left menu.Instead of storing the DataTable in ViewState and converting it to DataTable again can you suggest something.

Thanks
0
 
LVL 25

Assisted Solution

by:Rouchie
Rouchie earned 2000 total points
ID: 38363649
What are the values within the DataTable/ViewState?  What do they represent and how are they being used?
0
 

Author Comment

by:KavyaVS
ID: 38372540
Hi Rouchie,

On web page left menu links,when the link is clicked I am getting DataTable back from ViewState and accessing the Xml contents column and decoding it to Html and showing it in webpage.

Everytime when the link is clicked I am not accessing the DataBase.I am getting the DataTable back from ViewState.I am looking for something more efficient than this.

Protected Sub lnk_Click(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim s As LinkButton = CType(sender, LinkButton)
            Dim sID As String = s.ID.ToString()
            Dim sAdDetails As String = String.Empty
            Dim dtAd As New DataTable
            dtAd = CType(ViewState("AdDetailsTable"), DataTable)
           
           
            Dim drFilteredRow As DataRow() = dtAd.Select("Ad_Code = " & Convert.ToInt16(sID.ToString()))
            For Each dr As DataRow In drFilteredRow
               
                sAdDetails = dr("Ad_Detail").ToString()
            Next
            sAdDetails = Server.HtmlDecode(sAdDetails.Replace("<AdContents>", "").Replace("</AdContents>", ""))
            vgAdDetails.InnerHtml = sAdDetails
          Catch ex As Exception
           
    End Sub

Thanks
0
 
LVL 25

Assisted Solution

by:Rouchie
Rouchie earned 2000 total points
ID: 38372716
To be honest, a database hit for each link would likely use LESS resources that the ViewState approach.  If the XML content doesn't change, you could store it in SESSION or CACHE.  Session is a per-user object that holds the data in memory until the user leaves the site - each users get their own portion of the Session memory.  Therefore a lot of users will slow down the server.  Cache allows the same memory to be accessed by everyone, so they all see the same data.  Useful for sharing.
0
 

Author Comment

by:KavyaVS
ID: 38376476
Hi Rouchie,
If I am hitting the Database eachtime for each link it is taking time to load the advertisement.It is an internet application and lot of users means it definitely slows down the server.

The XML content doesn't change.I tried both Session and ViewState for storing the DataTable.But they are still slow.
 You mentioned Cache allows the same memory to be accessed by everyone, so they all see the same data.  Useful for sharing.


How to store the DataTable in cache.

Thanks.
0
 
LVL 25

Accepted Solution

by:
Rouchie earned 2000 total points
ID: 38376535
First create a subroutine that accesses your database and loads the values...

Protected Sub LoadDataIntoCache()
    ' use your existing database code here until you have your datatable...
    Cache("myDT") = myDataTableVariable
End Sub

Open in new window


Then on each linkbutton you can do this:

Protected Sub lnk_Click(ByVal sender As Object, ByVal e As EventArgs)
    If Cache("myDT") Is Nothing Then
         LoadDataIntoCache() ' make sure DataTable always exists
    End If
    Dim myDataTable as DataTable = Cache("myDT")
    ' use data table here
End Sub

Open in new window


The only catch is that every time your database gets changed (e.g. your data changes) you have to reload Cache to get the most recent data.  So in your ASP.NET database update/insert code make sure you always call LoadDataIntoCache() after the data is changed!
0
 

Author Closing Comment

by:KavyaVS
ID: 38398672
Thanks
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Loops Section Overview

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question