DotNet Tutorials

Server Intellect

 Store data with Hashtable using ASP.NET 2.0 and VB.NET

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

If you're looking for a really good web host, try Server Intellect - we found the setup procedure and control panel, very easy to adapt to and their IT team is awesome!

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

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>

The flow for the code behind page is as follows

We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!

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.DotNetTutorials.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



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

Looking for more ASP.NET Tutorials? Click Here!
Download Project Source - Enter your Email to be emailed a link to download the Full Source Project used in this Tutorial!



100% SPAM FREE! We will never sell or rent your email address!
 
123 ASP

411 ASP

Dot Net Freaks

Server Intellect