User-939850651 posted
Hi Mohammed Tajudeen,
Based on the code you provided, I think the main problem is unnecessary loop nesting.
For Each column As DataColumn In ds.Tables(0).Columns
'Add the Data rows.
txt += row(column.ColumnName).ToString() & vbTab & vbTab
Next
When you traverse to each row of the same dataTable ( Tables(0) ), you will execute this loop, and it will get the same result. Therefore it is redundant, and it will reduce your operating efficiency.
I think you can move this part out of the outer loop, define the result as a variable and just use it. Something like this:
'txt += vbCr & vbLf
Dim columnNales as String
For Each column As DataColumn In ds.Tables(0).Columns
'Add the Data rows.
columnNales += row(column.ColumnName).ToString() & vbTab & vbTab
Next
If ds.Tables(0).Rows.Count > 0 Then
For Each row As DataRow In ds.Tables(0).Rows
'Add new line.
txt += columnNales & vbCr & vbLf
Next
fp.WriteLine(txt)
fp.Close()
...
End If
Best regards,
Xudong Peng