hi i have the following code which populates a data by a datareader into a literal control ( txtMenu) on my webform
how can i cache this data !! shoudl i use dataTable or Gridview(with this caching ability)!!
Dim strConnString As [String] = HttpContext.Current.Cache("con")
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getMenuItems"
cmd.Connection = con
Try
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
While dr.Read()
txtMenu.Text += "<div class='menuItem2'><div class='menuBullet'><img src='images/bullet.gif' width='5' height='5'></div><div class='menuText2'><a href='" & config.applicationURL & "/gold.aspx?id=" & dr("ID").ToString & "' class='menus2'>"
& dr("category").ToString & "</a></div></div>"
End While
dr.Close()
Catch ex As Exception
Throw ex
Dim con As New SqlConnection(strConnString)
con.Open()
Dim rd As SqlDataReader
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getMenuItems"
cmd.Connection = con
rd = cmd.ExecuteReader()
GridView1.DataSource = rd
GridView1.DataBind()
rd.Close()
con.Close()
Fill DataTable:
Dim con As New SqlConnection(strConnString)
con.Open()
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getMenuItems"
cmd.Connection = con
Dim tab As New DataTable()
Dim adapter As New SqlDataAdapter(cmd)
adapter.Fill(tab)
con.Close()
Please mark the replies as answers if they help or unmark if not.
Feedback to us
keyvan1
Member
86 Points
272 Posts
how to cache this into a dataTable
Nov 11, 2012 03:02 PM|LINK
hi i have the following code which populates a data by a datareader into a literal control ( txtMenu) on my webform
how can i cache this data !! shoudl i use dataTable or Gridview(with this caching ability)!!
Dim strConnString As [String] = HttpContext.Current.Cache("con")
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "getMenuItems"
cmd.Connection = con
Try
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
While dr.Read()
txtMenu.Text += "<div class='menuItem2'><div class='menuBullet'><img src='images/bullet.gif' width='5' height='5'></div><div class='menuText2'><a href='" & config.applicationURL & "/gold.aspx?id=" & dr("ID").ToString & "' class='menus2'>" & dr("category").ToString & "</a></div></div>"
End While
dr.Close()
Catch ex As Exception
Throw ex
Finally
con.Close()
con.Dispose()
End Try
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: how to cache this into a dataTable
Nov 13, 2012 10:07 AM|LINK
Bind GridView:
Fill DataTable:
Feedback to us
Develop and promote your apps in Windows Store
keyvan1
Member
86 Points
272 Posts
Re: how to cache this into a dataTable
Nov 13, 2012 01:50 PM|LINK
OK But my question was sth else
HOW TO CACHE this and return the cached item!!!!
Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: how to cache this into a dataTable
Nov 14, 2012 01:09 AM|LINK
Create data cache for your DataTable:
Cache["myTable"] = "DataTable Name"
Convert cache into datatable:
GridView1.DataSource = (DataTable)Cache["myTable"];
GridView1.DataBind();
http://msdn.microsoft.com/en-us/library/system.web.caching.cache.aspx
Feedback to us
Develop and promote your apps in Windows Store