Click here to Skip to main content
13,293,369 members (55,478 online)
Click here to Skip to main content
Add your own
alternative version


23 bookmarked
Posted 3 Aug 2004

Setting and retrieving a Dataset in a Hashtable

, 3 Aug 2004
Rate this:
Please Sign up or sign in to vote.
Beginner tutorial on settting and retrieving dataset values from a hashtable


This is a kindergarten tutorial on how to add a dataset as a hashtable entry item and how to retrieve the values from the hashtable.


I was looking out for a class in .NET that resembled the propertyBag. What a relief when I found this class on msdn.


Hashtable is a class in System.Collections. It is a collection of key-and-value pairs that are organized based on the hash code of the key.

The Code

The file in the source code contains a function GetHashTable() to set a dataset into a hashtable and return it to the calling function. First we create a new hashtable, like so
Dim htbl As System.Collections.Hashtable = New System.Collections.Hashtable()
The dataset is populated using a DataSet.ReadXml.
Dim ds As DataSet = New DataSet()
Next we add the populated dataset onto the hashtable and return it. The syntax for the add is as follows
Public Overridable Sub Add(ByVal key As Object, ByVal value As Object) _
  Implements IDictionary.Add
The key is the element to add, and the value is the value of the key to add. So we add the dataset into the Hashtable and return the hashtable to the calling function.
htbl.Add("CustomerDetails", ds)
Return htbl
Now getting on to the calling function. We call GetHashTable() which will return a Hashtable. We now try to get the dataset back from the Hashtable. The Hashtable stores the key-value pairs based on the hash code of the key. This way, we can access the key value by doing a lookup of the key.
ds = htbl("CustomerDetails")
Now you got the dataset from the hashtable.

That was a very basic code!

The purpose of the article was to explain the concept behind adding in and retrieving objects from the hashtable. However the real purpose of using the hashtable goes much beyond this. This article is just to get u started up on Hashtables.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Tingz Abraham
United States United States
When Tingz Abraham was old enough to realize that computers were going to invade the world, he decided to pursue a career that would keep him close to computers. That landed him a job as an IT Solutions Consultant in Seattle, USA where he currently works. He believes he can program in many languages, including English. Ctrl+C and Ctrl+V are his favorite keys on the keyboard.

After he found he sucked real bad at playing the violin, he just stuck to the guitar and piano. He has a ravishing need for speed and takes a fancy to anything with wheels, including his black Mustang which he's aptly named 'Tingzmobile'.

At work you can constantly hear him say - "Oh! The things I learn after I know it all!" He keeps himself very busy, and in his spare time he keeps wondering why '24 hours a day is just not enough'.

He exists at

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 4 Aug 2004
Article Copyright 2004 by Tingz Abraham
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid