superwei

导航

<2025年1月>
2930311234
567891011
12131415161718
19202122232425
2627282930311
2345678

统计

常用链接

留言簿(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 小辞猬 阅读(1220) 评论(0)  编辑  收藏 所属分类: DoNet


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


网站导航: