13.07.2015 Views

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

Applied XML Programming for Microsoft .NET.pdf - Csbdu.in

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}The net effect of this code is that any changes entered <strong>in</strong> the source CSV document arecached to a temporary file, which then replaces the orig<strong>in</strong>al. The user won't perceiveanyth<strong>in</strong>g of these work<strong>in</strong>gs, however.The CSV Reader/Writer <strong>in</strong> ActionLet's take a sample CSV file, read it, and apply some changes to the contents so thatthey will automatically be persisted when the reader is closed. Here is the source CSVfile:LastName,FirstName,Title,CountryDavolio,Nancy,Sales Representative,USAFuller,Andrew,Sales Manager,USALeverl<strong>in</strong>g,Janet,Sales Representative,UKSuyama,Michael,Sales Representative,UKThe idea is to replac<strong>in</strong>g the expression Sales Representative with another one—say,Sales Force. The sample application, nearly identical to the one <strong>in</strong> Chapter 2, loads theCSV file, applies the changes, and then displays it through a desktop DataGrid control,as follows:// Instantiate the reader on a CSV fileXmlCsvReadWriter reader;reader = new XmlCsvReadWriter("employees.csv",hasHeader.Checked);reader.EnableOutput = true;reader.Read();// Def<strong>in</strong>e the schema of the table to b<strong>in</strong>d to the gridDataTable dt = new DataTable();<strong>for</strong>(<strong>in</strong>t i=0; i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!