By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,711 Members | 1,368 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,711 IT Pros & Developers. It's quick & easy.

Need help storing data

P: n/a
Hello all,

I am a VB.NET beginner who is unfamilier with all the different
collection types that VB.NET has to offer. I am in need of a way to
store multiple elements which can be retrieved with a unique key
(string). For example, I would like to store characteristics like first
name, last name, age, and phone number and associate them with the
unique key like a USERID. Then loop through the data collection and
pull certain elements out for processing. Which collection type would
be best suited for this purpose?

Thanks!

Nov 21 '05 #1
Share this Question
Share on Google+
5 Replies

P: n/a
Paulers,

The Hashtable is a collection that implements key/value storage.

Kerry Moorman
"Paulers" wrote:
Hello all,

I am a VB.NET beginner who is unfamilier with all the different
collection types that VB.NET has to offer. I am in need of a way to
store multiple elements which can be retrieved with a unique key
(string). For example, I would like to store characteristics like first
name, last name, age, and phone number and associate them with the
unique key like a USERID. Then loop through the data collection and
pull certain elements out for processing. Which collection type would
be best suited for this purpose?

Thanks!

Nov 21 '05 #2

P: n/a
Paulers,

As you say it already in your message you need a table for your data that
can have a primary key.

In other words the "datatable".

I hope this helps,

Cor
Nov 21 '05 #3

P: n/a
"Paulers" <Su*******@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
I am in need of a way to store multiple elements which can be
retrieved with a unique key (string). For example, I would like to
store characteristics like first name, last name, age, and phone number
and associate them with the unique key like a USERID. Then loop
through the data collection and pull certain elements out for
processing. Which collection type would be best suited for this purpose?


/Any/ of them really, because what you'll be placing into the "collection"
is a class of your own devising that contains all these properties.

HashTable is probably the easiest, though.

Public Class Person
Public Sub New( Username as String, ...
Public ReadOnly Property Age() as Integer
Public Property DoB() as DateTime
Public Property Forename() as String
Public Property Phone() as String
Public Property Surname() as String
Public ReadOnly Property Username() as String
End Class

Dim htPeople as New HashTable

htPeople.Add( "fred", New Person( "fred", ... ) )

Dim employee as Person _
= DirectCast( htPeople.Item( "fred" ), Person )

Bear in mind, though, that some collections hold things internally
as DictionaryEntry objects, so you might have to do an extra layer
of "translation" when iterating through the items therein.

HTH,
Phill W.
Nov 21 '05 #4

P: n/a
Thanks for the example! Can I talk you into an example showing how to
retrieve the information from the HashTable? I really appreciate the
help.

Nov 21 '05 #5

P: n/a
I understand that you are storing objects in the collection, but in the
Person Class how are the properties getting set? I see the declaration
but I dont see set and get methods. Do I need them in the example
above? Don't I have to define the values of each property?

Nov 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.