Thursday, 23 February 2012

How to export DataTable to CSV File Format

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim Con As String = ConfigurationManager.ConnectionStrings("ConnectionString").ToString()

    Dim conn As New SqlConnection(Con)

    Dim da As New SqlDataAdapter("select * from employees", conn)

    Dim ds As New DataSet()

    da.Fill(ds, "Emp")

    GridView1.DataSource = ds.Tables("Emp").DefaultView


    Dim dt As DataTable = ds.Tables("Emp")

    CreateCSVFile(dt, "c:\csvData.csv")

End Sub

1 comment:

  1. Break 19, Whats the 20 on CreateCSVFile Sub-Routine? That was the title of this article