superwei

导航

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

统计

常用链接

留言簿(4)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜

VB.NET2003 DataSet导出到CSV代码(原创)

    Public Function OutPutCSV(ByVal FileName As String, ByVal DataTable As DataSet, Optional ByVal TableIndex As Integer = 0) As Boolean
        Dim fw As StreamWriter
        Dim myRow As DataRow
        Dim myCol As DataColumn
        Try
            fw = New StreamWriter(FileName, True)
            For Each myCol In DataTable.Tables(TableIndex).Columns
                If myCol Is DataTable.Tables(TableIndex).Columns(DataTable.Tables(TableIndex).Columns.Count - 1) Then
                    fw.WriteLine(myCol.Caption)
                Else
                    fw.Write(myCol.Caption)
                    fw.Write(",")
                End If
            Next myCol
            For Each myRow In DataTable.Tables(TableIndex).Rows
                For Each myCol In DataTable.Tables(TableIndex).Columns
                    If myCol Is DataTable.Tables(TableIndex).Columns(DataTable.Tables(TableIndex).Columns.Count - 1) Then
                        fw.WriteLine(myRow(myCol))
                    Else
                        fw.Write(myRow(myCol))
                        fw.Write(",")
                    End If
                Next myCol
            Next myRow
            Return True
        Catch e As Exception
            MessageBox.Show(e.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Return False
        Finally
            fw.Close()
        End Try
    End Function

posted on 2007-09-27 16:11 小辞猬 阅读(1218) 评论(0)  编辑  收藏 所属分类: DoNet


只有注册用户登录后才能发表评论。


网站导航: