Link to home
Start Free TrialLog in
Avatar of KavyaVS
KavyaVS

asked on

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

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,
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

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.
Put a sample code here which can reflect your issue for us , so we can suggest any ideas to improve .

Meeran03
SOLUTION
Avatar of Rouchie
Rouchie
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KavyaVS
KavyaVS

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KavyaVS

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KavyaVS

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of KavyaVS

ASKER

Thanks