write to textfile?

Joined
Jun 6, 2008
Messages
9
Programming Experience
Beginner
hey friends, im a begginner in vb.net, can i ask for idea how could i write this data inside the datable to a textfile,

example,


test1
test2
test3
test4
test5
test6
test7
test8
test9
test10


into a textfile looks like this

test1,test2,test3,test4,test5,
test6,test7,test8,test9,test10,


i try to use this code but i dont know how can use the writeline command to write vertical data into horizontal.

VB.NET:
   Dim DT As DataTable
        Dim strCommand As String = ""
        Dim strBatchFile As String = ""
        Dim Counter As Integer = 0

        For Each objRow As DataRow In DT.Rows
            Counter = Counter + 1
            If strCommand = "" Then
                strCommand = objRow!test
            Else
                strCommand = strCommand & ", " & objRow!test            
      End If

            If Counter >= 5 Then
                strBatchFile = strBatchFile & vbCrLf & strCommand
                strCommand = ""
                Counter = 0
            End If

        Next

Thanks for help and more power.
 
write to a textfile?

right, i want to export the contents of the my datable, i have only one row in my datatable and i want to export it in a textfile. just like my example above. any one can help me? thanks in advance.:confused::confused:
 
datatable.writexml

But simplistically:
VB.NET:
StringBuilder sb = new StringBuilder();
For Each ro as DataRow in myDataTable.Rows
  sb.AppendFormat("{0},", ro(0))
Next ro
sb.Length -= 1
File.WriteAllText("C:\temp.txt", sb.ToString())
 
Last edited:
Back
Top