How do I convert an ArrayList to a dataset?

Hello,

I have an ArrayList holding a specific object type. I need to convert into a dataset so I can write it to an .xml file format and then export it to a report. Anyone know how to do this?

Thank you,

Zac
LVL 1
saculAsked:
Who is Participating?
 
prosh0tConnect With a Mentor Commented:
Hello Zac,
I think this is your solution:

Dim dsTemp As DataSet = New DataSet
Dim dTbl As New DataTable

dTbl.Columns.Add("myColumn")
dsTemp.Tables.Add(dTbl)
Dim arr As New ArrayList
arr.Add("1")
arr.Add("2")
arr.Add("3")
arr.Add("4")
Dim str As String

For Each str In arr
    Dim dRow As DataRow
    dRow = dTbl.NewRow()
    dRow("myColumn") = str
    dTbl.Rows.Add(dRow)
Next

dsTemp.WriteXml("c:\test.xml")


hope this helps.  Good luck.

0
 
cubixSoftwareCommented:
Couple of questions

1. What object type is held
2. Why don't you simply loop thru your arraylist and build the XML format

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.