Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

How do I roll up data as follows...

  Asked By: Caleb    Date: Nov 21    Category: Asp.net    Views: 963
  

I have a datatable (name, ID) like

Name ID

Sample 1
Sample 4
Other 6
Sample 5


I would like to get the datatable in a format such (name, array of
IDS)
as

Name IDS
Sample {1,4,5}
Other {6}


Any ideas for a clean approach to accomplish this?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Richie Smith     Answered On: Nov 21

so... i think that you can use a hash table with your array  in the
value.


protected HashTable MyTable

class(....

this.MyTable = New HashTable(4); // for 4 items in the table

//add the item into your table.


this.MyTable.Add("Sample",MyArray);


//..... and so on...

than you use:

string[] NewArray = (int[])MyTable["Sample"];

hope it helps.

new Hashtable(4);

 
Answer #2    Answered By: Emma Brown     Answered On: Nov 21

Have you looked at a DataRelation?

 
Answer #3    Answered By: Willie Gomez     Answered On: Nov 21

ok here it is.....


DIM ht1 as new hashtable
Dim datarow1 As DataRow
DIM strName as string
DIM intID as integer
FOR EACH datarow1 IN dt1.Rows
strName=datarow1(0)
intID=datarow(1)
IF ht.contains(strName)
ht(strName) = ht(StrName) & "," & intID
ELSE
ht(StrName)="{" & intID

END IF
NEXT
ht(StrName)= & "}"

' Now the hash table has what you want ....

http://www.learnasp.com/freebook/learn/hashtable.aspx
shows you most of what you need to know about hashtable.

 
Didn't find what you were looking for? Find more on How do I roll up data as follows... Or get search suggestion and latest updates.




Tagged: