Server Intellect
 
Home   Asp.Net Tutorials   What's New   Newsletter   More Resources
 
 
  Categories
Advanced Technologies
AJAX
Internet Browsers
Controls
Database
Email
Error Handling
File
Graphics
Website Navigation
Network
Performance
User Interface and Themes
Validation
Visual Web Developer
Web Services
XML
Suggest Tutorial


Navigator: Home - Tutorials - Advanced Technologies - Store data with Hashtable using ASP.NET 2.0 and VB.NET
Store data with Hashtable using ASP.NET 2.0 and VB.NET


ASP.NET Advanced Technologies Tutorial

This tutorial will show you how to store data with Hashtable using ASP.NET 2.0 and VB.NET.

At first, you need to import the namespace from System.Collections.The System.Collections namespace contains classe Hashtable which represents a collection of key/value pairs that are organized based on the hash code of the key. 

Imports System.Collections

Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!

In order to run the example, we will use the btn_get_Click to trigger the task. The code as following:

Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click
Dim key As Integer
Dim name As String = String.Empty
Dim str As String = String.Empty

Dim hashtable As Hashtable = New Hashtable()
key = 1
name = "Jake"
Hashtable.Add(key, name)
key = 2
name = "peter"
Hashtable.Add(key, name)
key = 3
name = "lily"
Hashtable.Add(key, name)

For Each de As DictionaryEntry In hashtable
str = str + "key=" + CType(de.Key, String) + " " + " value=" + de.Value.ToString() + "<br>"
Next de
Me.Label1.Text = str
End Sub

Try Server Intellect for Windows Server Hosting. Quality and Quantity!

The front end StoreDataWithHashtableVB.aspx page looks something like this:

<div align="left" style="text-align: center">
&nbsp;<table>
<tr>
<td colspan="2" style="width: 402px">
<asp:Label ID="Label1" runat="server"></asp:Label>
&nbsp;</td>
</tr>
<tr>
<td colspan="2" style="height: 26px; width: 402px;">
<asp:Button ID="btn_get" runat="server" Text="Get data from hashtable" OnClick="btn_get_Click"/></td>
</tr>
</table>
&nbsp;&nbsp;
</div>

Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.

The flow for the code behind page is as follows

Imports System.Collections
Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' This tutorial is provided in part by Server Intellect Web Hosting Solutions http://www.serverintellect.com
' Visit http://www.AspNetTutorials.com for more ASP.NET Tutorials
End Sub

Protected Sub btn_get_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_get.Click
Dim key As Integer
Dim name As String = String.Empty
Dim str As String = String.Empty

Dim hashtable As Hashtable = New Hashtable()
key = 1
name = "Jake"
Hashtable.Add(key, name)
key = 2
name = "peter"
Hashtable.Add(key, name)
key = 3
name = "lily"
Hashtable.Add(key, name)

For Each de As DictionaryEntry In hashtable
str = str + "key=" + CType(de.Key, String) + " " + " value=" + de.Value.ToString() + "<br>"
Next de
Me.Label1.Text = str
End Sub
End Class

Download the Full Working Version of this Project written with Visual Studio.NET VB.NET 2005 Here!

Looking for the C#.NET 2005 Version? Click Here!

Looking for more ASP.NET Tutorials? Click Here!





 
  Developer Resources







Server Intellect Rocks