DataTable2CSV – Saving a DataTable to a CSV file

DataTable2CSV – Saving a DataTable to a CSV file

' Save the input DataTable to a CSV file. By default the values are Tab ' delimited, but you can use the second overload version to use any other ' string you want.'' Example:'    Dim ds As New DataSet'    SqlDataAdapter1.Fill(ds, "Users")'    DataTable2CSV(ds.Tables("Users"), "D:Users.txt")Sub DataTable2CSV(ByVal table As DataTable, ByVal filename As String)    DataTable2CSV(table, filename, vbTab)End SubSub DataTable2CSV(ByVal table As DataTable, ByVal filename As String, _    ByVal sepChar As String)    Dim writer As System.IO.StreamWriter    Try        writer = New System.IO.StreamWriter(filename)        ' first write a line with the columns name        Dim sep As String = ""        Dim builder As New System.Text.StringBuilder        For Each col As DataColumn In table.Columns            builder.Append(sep).Append(col.ColumnName)            sep = sepChar        Next        writer.WriteLine(builder.ToString())        ' then write all the rows        For Each row As DataRow In table.Rows            sep = ""            builder = New System.Text.StringBuilder            For Each col As DataColumn In table.Columns                builder.Append(sep).Append(row(col.ColumnName))                sep = sepChar            Next            writer.WriteLine(builder.ToString())        Next    Finally        If Not writer Is Nothing Then writer.Close()    End TryEnd Sub

Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved