Türkçe   |   English
Calendar
ArticleCategories
Article Archive
Most Read Articles
Links
Blogroll
Files

Extended DataTable
Publish Date 31.03.2007
Categories C#
Views 291
Summary
ExtendedDataTable is a component which provides more functionality compared to native .NET Framework DataTable. It is also platform independent, you can use it with Web or Windows applications. It is developed by .NET Framework 2.0 and .NET Framework 3.5, you can download both versions from this page. Let's look at what functionalities ExtendedDataTable provides.

Introduction

ExtendedDataTable is a component which provides more functionality compared to native .NET Framework DataTable. It is also platform independent, you can use it with Web or Windows applications. It is developed by .NET Framework 2.0 and .NET Framework 3.5, you can download both versions from this page. Let's look at what functionalities ExtendedDataTable provides.

Background

It always takes time for developers writing code to export data to external file types such as Word, Excel, HTML. Developers also spending time for some actions such as printing a report, sending a mail. This is a time saving component which gives the benefit to developers to use these functionalities quickly.

Using the Code

Methods

  • ToWord: Exports the data into a Word document in client's computer as a table object
  • ToExcel: Exports the data as Excel worksheet in client's computer
  • ToHtml: Generates the HTML code using table, tr, td tags that represent data
  • SendMail: Allows users to send the HTML table that represents data as email
  • Print: Prints the data to any printer
  • Fill: Easily fills table with data from database with the DataAdapter component it includes
  • Update: Allows users to easily update data to database with DataAdapter component it includes

Properties

  • StyleProperties: You can easily modify the style of the table which will be generated, such as Table Style, Row Style, Header Style, Alternating Row Style, Row Specific Style by this property.
  • FormatProperties: This property allows users to change the format of the table which will be generated, such as Column Headers, Column Alignments and Column Formats (number, date formats).
  • PrintProperties: By using this property, you can easily modify the layout of the document which will be printed or the properties of the printer.
  • MailProperties: This property is used to change the settings for SMTP Server.
  • DataProperties: This property allows users to modify the settings for Connection, Command, DataAdapter components to fill or update data.

Let me explain the technology that is used to provide these functionalities:

  • ToWord and ToExcel methods Office Interop is used to create and fill the documents.
  • ToHtml is a simple method that generates the HTML code using tr, td, table tags by iterating through rows and columns.
  • SendMail creates a MailMessage object and sends the HTML code generated by SmtpServer.
  • Print method works differently for Windows and Web applications:
    • For Windows applications, it uses Graphic objects methods like MeasureString, DrawRectangle, FillRectangle and DrawString for generating the document to be printed.
    • For Web applications, it writes generated HTML code to current response and calls javascript window.print method.
  • Fill and Update methods uses dataadapter to select, insert and update data to database.

You can find information about how to use this component in a sample application provided in the download.

ExtendedDataTable extendedDt = new ExtendedDataTable();
DataSet ds = new DataSet();
ds.ReadXml("SampleData.xml");
DataTable dt = ds.Tables[0];
 
extendedDt.ImportDataTable(dt);
 
extendedDt.FormatProperties.ColumnNames["FriendId"] = "Id";
extendedDt.FormatProperties.ColumnNames["FriendName"] = "Name";
extendedDt.FormatProperties.ColumnNames["FriendSurname"] = "Surname";
extendedDt.FormatProperties.ColumnNames["Gender"] = "Gender";
extendedDt.FormatProperties.ColumnNames["PlayedBy"] = "Played By";
 
//Export To Word
extendedDt.ToWord(@"C:\Friends.docx");
 
//Export To Excel
extendedDt.ToExcel(@"C:\Friends.xlsx");
 
//ToHtml
MessageBox.Show(extendedDt.ToHTML());
 
//SendMail
extendedDt.MailProperties.SmtpClient.Host = "localhost";
extendedDt.SendMail("oztamer@hotmail.com", "oztamer@hotmail.com", "Friends");
 
//Print
extendedDt.PrintProperties.PrintDocument.DefaultPageSettings.Landscape = true;
extendedDt.Print();
 
//Fill
extendedDt.DataProperties.Connection.ConnectionString = 
    "data source=.;initial catalog=dummy;integrated security=SSPI";
extendedDt.DataProperties.Command.CommandText = "SELECT * FROM Dummy";
extendedDt.Fill();
 
//Update
extendedDt.Update();

History

  • Initial release: 19.01.2008 V 1.0.0
    For bug reports and suggestions, feel free to contact me at oztamer@hotmail.com.

Download Source

CodeProject

Add Comment
First Name Last Name
Web Site
E-Mail
Comment
Security Picture

Photos

Three pyramids and me
Show All
Me in MSDN Forums
-   Answered the question Close some open windows by name in the Visual C# General forum
-   Answered the question Close some open windows by name in the Visual C# General forum
-   Answered the question Datagridview Click Event in C#.net in the Visual C# General forum
-   Contributed a proposed answer to the question Close some open windows by name in the Visual C# General forum
-   Replied to the question Datagridview Click Event in C#.net in the Visual C# General forum
-   Replied to the question Close some open windows by name in the Visual C# General forum
-   Contributed a helpful post (total votes:2) to the forums thread Array of events? in the Visual C# General forum
-   Answered the question Displaying random images from resources in the project in the Visual C# Language forum
-   Contributed a helpful post (total votes:1) to the forums thread sorted dictionary (Can i get key from value) in the Visual C# General forum
-   Contributed a proposed answer to the question Non-existing Argument in format string in the Visual C# General forum
Entries
News
Articles