Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i want to implement hashtable for the below scenario.

i have data in a table like.

Model Number Part number
xxx iu 234
ZZZ 123
yyy 213
abc 890
xxx 234


i want to trace how many times a model is repeated. and if the model is already in hashtable i want to increment model count else add it to hashtable.

but in my code it's updating value when it contains a model.
i dono how to implement pls help me.

and another question should i increment key value (when ever i added to hashtable)?

below is code how i am implementing...

i got all these rows into a datarow.
By looping into datarow,i want to implement hashtable for modelnumber.


VB
For Each aceDAERow In aceDAERows

 If aceDAERowHash.ContainsValue(aceDAERow.Item("Model_Number")) Then
        aceDAERowHash(modelnumber) = aceDAERowHash(modelnumber) + 1
 Else
       aceDAERowHash.Add(modelnumber, aceDAERow.Item("Model_Number"))
 End If
 modelnumber = modelnumber + 1

 Next



Thanks in advance.
Posted
Comments
sachin10d 19-Sep-11 12:30pm    
Dictionary should be used instead of hashtable.

1 solution

I think this will work (caveat - I didn't test this, so you may need to tweak it).

VB
Dim hash As New Dictionary(Of String, Integer)()

If hash.Containskey(name) Then
	hash(name).Value += 1
Else
	hash.Add(name, 1)
End If
 
Share this answer
 
Comments
subhash04573 19-Sep-11 21:43pm    
thank you very much

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900