CSV Reports
CsvStreamToDataReader Method
Example 



KellermanSoftware.CsvReports Namespace > CsvReader Class : CsvStreamToDataReader Method
A CSV stream
Create a forward only reader for a CSV stream
Syntax
Public Function CsvStreamToDataReader( _
   ByVal stream As Stream _
) As IDataReader
Dim instance As CsvReader
Dim stream As Stream
Dim value As IDataReader
 
value = instance.CsvStreamToDataReader(stream)
public IDataReader CsvStreamToDataReader( 
   Stream stream
)
public:
IDataReader^ CsvStreamToDataReader( 
   Stream^ stream
) 

Parameters

stream
A CSV stream

Return Value

A data reader
Example
CsvReader csvReader = new CsvReader(); //Trial Mode
//CsvReader csvReader = new CsvReader("place user name here", "place license key here"); //License Mode
 
//Create a test file
string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv");
File.WriteAllText(filePath, "Name,Birthdate\r\nJohn,5/30/2013");
 
using (FileStream stream = new FileStream("testReader.csv", FileMode.Open))
{
    using (IDataReader dataReader = csvReader.CsvStreamToDataReader(stream))
    {
        while (dataReader.Read())
        {
            Console.WriteLine("Name: " + dataReader.GetString(dataReader.GetOrdinal("Name")));
            Console.WriteLine("Birthdate: " + dataReader.GetDateTime(dataReader.GetOrdinal("Birthdate")));
        }
    }
}
Imports Microsoft.VisualBasic
 
Dim csvReader As New CsvReader() 'Trial Mode
'CsvReader csvReader = new CsvReader("place user name here", "place license key here"); //License Mode
 
'Create a test file
Dim filePath As String = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testReader.csv")
File.WriteAllText(filePath, "Name,Birthdate" & vbCrLf & "John,5/30/2013")
 
Using stream As New FileStream("testReader.csv", FileMode.Open)
    Using dataReader As IDataReader = csvReader.CsvStreamToDataReader(stream)
        Do While dataReader.Read()
            Console.WriteLine("Name: " & dataReader.GetString(dataReader.GetOrdinal("Name")))
            Console.WriteLine("Birthdate: " & dataReader.GetDateTime(dataReader.GetOrdinal("Birthdate")))
        Loop
    End Using
End Using
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

CsvReader Class
CsvReader Members