CSV Reports
DataTableToCsvWriter(TextWriter,DataTable) Method
Example 



KellermanSoftware.CsvReports Namespace > CsvWriter Class > DataTableToCsvWriter Method : DataTableToCsvWriter(TextWriter,DataTable) Method
The output text writer
The table to output
Output the rows of a data table to a text writer
Syntax
Public Overloads Sub DataTableToCsvWriter( _
   ByVal writer As TextWriter, _
   ByVal table As DataTable _
) 
Dim instance As CsvWriter
Dim writer As TextWriter
Dim table As DataTable
 
instance.DataTableToCsvWriter(writer, table)
public void DataTableToCsvWriter( 
   TextWriter writer,
   DataTable table
)
public:
void DataTableToCsvWriter( 
   TextWriter^ writer,
   DataTable^ table
) 

Parameters

writer
The output text writer
table
The table to output
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
 
//Parameters
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 filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv");
 
using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
    using (TextWriter writer = new StreamWriter(stream))
    {
        csvWriter.DataTableToCsvWriter(writer,table);
    }
}
 
Console.WriteLine(File.ReadAllText(filePath));
'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
 
'Parameters
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 filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testWriter.csv")
 
Using stream As New FileStream(filePath, FileMode.Create, FileAccess.Write)
    Using writer As TextWriter = New StreamWriter(stream)
        csvWriter.DataTableToCsvWriter(writer,table)
    End Using
End Using
 
Console.WriteLine(File.ReadAllText(filePath))
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