CSV Reports
DataTableToCsvString(DataTable) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > DataTableToCsvString Method : DataTableToCsvString(DataTable) Method
The table to output
Create a CSV String from a data table
Syntax
Public Overloads Function DataTableToCsvString( _
   ByVal table As DataTable _
) As String
Dim instance As CsvWriter
Dim table As DataTable
Dim value As String
 
value = instance.DataTableToCsvString(table)
public string DataTableToCsvString( 
   DataTable table
)
public:
String^ DataTableToCsvString( 
   DataTable^ table
) 

Parameters

table
The table to output

Return Value

CSV String
Example
//Example Class
public class Person
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime BirthDate { get; set; }
}
 
CsvWriter csvWriter = new CsvWriter(); //Trial Mode
//CsvWriter csvWriter = new CsvWriter("place user name here", "place license key here"); //License Mode
 
DataTable table = new DataTable();
table.Columns.Add("FirstName", typeof(string));
table.Columns.Add("LastName", typeof(string));
table.Columns.Add("BirthDate", typeof(string));
 
DataRow row = table.NewRow();
row["FirstName"] = "John";
row["LastName"] = "Smith";
row["BirthDate"] = DateTime.Now.AddDays(-1).ToString();
table.Rows.Add(row);
 
string results = csvWriter.DataTableToCsvString(table);
 
Console.WriteLine(results);
'Example Class
Public Class Person
    Public Property FirstName() As String
    Public Property LastName() As String
    Public Property BirthDate() As Date
End Class
 
Dim csvWriter As New CsvWriter() 'Trial Mode
'Dim csvWriter As New CsvWriter("place user name here", "place license key here") 'License Mode
 
Dim table As New DataTable()
table.Columns.Add("FirstName", GetType(String))
table.Columns.Add("LastName", GetType(String))
table.Columns.Add("BirthDate", GetType(String))
 
Dim row As DataRow = table.NewRow()
row("FirstName") = "John"
row("LastName") = "Smith"
row("BirthDate") = Date.Now.AddDays(-1).ToString()
table.Rows.Add(row)
 
Dim results As String = csvWriter.DataTableToCsvString(table)
 
Console.WriteLine(results)
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

CsvWriter Class
CsvWriter Members
Overload List