我想动态循环遍历结果集并捕获每一行(datarow)并写入文本文件,而不必手动指示行中的每个项目,如项目(0),项目(1),项目(2) )......等等。
Using sw As StreamWriter = New StreamWriter("C:\"file.txt")
For Each dr In ds.Tables("Table1").Rows
sw.WriteLine(dr.item(0).ToString() + "," + dr.item(1).ToString() +"," ...
Next
答案 0 :(得分:1)
您需要获取该行所属的表,以便您可以获取表中的列数然后循环。字符串连接需要一些工作,但我确定你会弄清楚
Using sw As StreamWriter = New StreamWriter("C:\"file.txt")
For Each dr In ds.Tables("Table1").Rows
Dim rowAsString as string
For i as integer = 0 to dr.Table.Columns.Count - 1
rowAsString += dr.item(i)
Next
sw.WriteLine(rowAsString)
Next