Dim i, j As Integer
Dim str As String = ""
For i = 0 To Mytable.Columns.Count - 1
str = Mytable.Columns(i).Caption
sw.Write(str & vbTab)
Next
sw.Write(vbCrLf)
For j = 0 To CType(datagrid.DataSource, DataTable).Rows.Count - 1
For i = 0 To CType(datagrid.DataSource, DataTable).Columns.Count - 1
Dim strColName, strRow As String
strRow = IIf(Mytable.Rows(j).Item(i) Is DBNull.Value, "", Mytable.Rows(j).Item(i))
sw.Write(strRow & vbTab)
Next
sw.Write(vbLf)
Next
sw.Close()
FS.Close()
MessageBox.Show("数据导出成功!", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Exit Function
End If
Else
MessageBox.Show("没有记录不能导出数据", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If