You can use Linq to Dataset:
Sample:
Dim arr() = dt.AsEnumerable().Select(Function(p)
Return New String(p("stdname") & "" & p("gender"))
End Function).ToArray()
System.IO.File.WriteAllLines("c:\csnet\p.txt", arr)
__avd
Posting Genius (adatapost)
8,736 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 50
PS: i need to save the data of each line in the Db to a single line in the txt file without space between the data.
I don't understand why you do not what a delimiter between the data as it will be nearly impossible to parse later. But you can always change your mind.
Perhaps a more old fashioned approach will be easier for you to understand.
Dim lines As New List(Of String)
For Each row As DataRow In dt.Rows
Dim line As String = String.Empty
For Each o As Object In row.ItemArray
line &= o.ToString
Next
lines.Add(line)
Next
System.IO.File.WriteAllLines("c:\csnet\p.txt", lines.ToArray)
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418
Solved Threads: 148
Skill Endorsements: 13
The space part is easy, remove if from tw.Write(", ").
As for the actual data, have you stepped through your code to see that the loop handling it works as planned?
A couple things I see wrong are:
Dim numRows As Integer = dgvData.RowCount - 1
For count As Integer = 0 To numRows - 1
you are deducting 1 twice when handling rows. If this is a datagridview with 1 row, then it won't fire.
Also
For count2 As Integer = 0 To numCols - 1
If (count2 <> numCols) Then
The if will never return false, as by definition count2 will never equal to number of columns (since you are limiting this in the for statement) .
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Please mark this thread as solved then.
Thanks.
adam_k
Veteran Poster
1,057 posts since Jun 2011
Reputation Points: 274
Solved Threads: 205
Skill Endorsements: 11
Question Answered as of 3 Months Ago by
adam_k,
__avd
and
TnTinMN