jfsedlar3rd
asked on
VB.NET Dataset datarow output.
Please help I am having a memory issue at the moment. I am writing a vb.net program using .NET 1.1 VS 2003. I have a dataset that contains multiple rows and about 166 columns. This information needs to be written to a text file. My question is how do I write each entire data row to the text file? For some reason i cannot get my code to return me the entire row.
ASKER
No, the file is a fixed length delimitation that I will be providing to an outside company.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim sb As New StringBuilder()
For Each dr As DataRow In dt.Rows
For Each dc As DataColumn In dt.Columns
sb.Append(dr(dc).ToString)
Next dc
' Write string builder to file.
Next dr
Bob
For Each dr As DataRow In dt.Rows
For Each dc As DataColumn In dt.Columns
sb.Append(dr(dc).ToString)
Next dc
' Write string builder to file.
Next dr
Bob
ASKER
Good point, I think that is what i have done in the past: Example
For each dr in ds.tables(0).rows
For Each DSCoulumn In ds.Tables(0).Columns
stringBuilder.add(ds.Table s(0).Rows( i).Item(j) .ToString( ))
j += 1
Next DSCoulumn
i+=1
Next
Am I on the right track?
For each dr in ds.tables(0).rows
For Each DSCoulumn In ds.Tables(0).Columns
stringBuilder.add(ds.Table
j += 1
Next DSCoulumn
i+=1
Next
Am I on the right track?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I was able to resolve this by using VBRocks code and making a few minor modifications.
Dim dt As New DataTable
Dim j As Integer
Dim dr As DataRow
Dim col As DataColumn
For i = 0 To ds.Tables(0).Columns.Count - 1
col = New DataColumn(ds.Tables(0).Co lumns(i).T oString)
dt.Columns.Add(col)
Next
'Add 50 rows of data to the DataTable, and populate every column
Dim row As DataRow
For i = 0 To ds.Tables(0).Rows.Count - 1
row = dt.NewRow()
For Each col In dt.Columns
'Insert row number and column number (Ordinal)
row.Item(col.Ordinal) = ds.Tables(0).Rows(i).Item( col.Ordina l)
Next
dt.Rows.Add(row)
Next
'Write each row out to a file
For Each row In dt.Rows
oWrite.WriteLine(Join(row. ItemArray) )
Next
oWrite.Close()
Dim dt As New DataTable
Dim j As Integer
Dim dr As DataRow
Dim col As DataColumn
For i = 0 To ds.Tables(0).Columns.Count
col = New DataColumn(ds.Tables(0).Co
dt.Columns.Add(col)
Next
'Add 50 rows of data to the DataTable, and populate every column
Dim row As DataRow
For i = 0 To ds.Tables(0).Rows.Count - 1
row = dt.NewRow()
For Each col In dt.Columns
'Insert row number and column number (Ordinal)
row.Item(col.Ordinal) = ds.Tables(0).Rows(i).Item(
Next
dt.Rows.Add(row)
Next
'Write each row out to a file
For Each row In dt.Rows
oWrite.WriteLine(Join(row.
Next
oWrite.Close()
Awesome! I'm glad I could help.
Could you just save the dataset as XML?