vb.net 中 datagridview的数据如何保存到 txt

求代码或者方法:vb.net 中 datagridview的数据如何保存到 txt
2024-12-05 05:15:48
推荐回答(1个)
回答1:

Dim i As Integer
Dim j As Integer
Dim myFile As New System.IO.StreamWriter("c:\Test.txt")
Dim strTemp As String = ""
For j = 0 To frmQuery.DataGridView1.RowCount - 1
strTemp = ""
For i = 0 To frmQuery.DataGridView1.Columns.Count - 1
strTemp &= "'" & frmQuery.DataGridView1(i, j).Value & "'" & ","
Next
myFile.WriteLine(strTemp)
Next
myFile.Close()
格式为表格每行保存为文本文件的一行,字段之间以逗号分隔。