Click here to Skip to main content
11,577,643 members (61,525 online)
Click here to Skip to main content

ExtendedDataTable

, 19 Jan 2008 Ms-PL 19.4K 732 17
Rate this:
Please Sign up or sign in to vote.
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.

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.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

Share

About the Author

Tamer Oz
Team Leader
Turkey Turkey
Tamer Oz is a Microsoft MVP and works as Assistant Unit Manager.

You may also be interested in...

Comments and Discussions

 
QuestionRetrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005. Pin
azmg525-Feb-10 7:16
memberazmg525-Feb-10 7:16 
Questionquestion? Pin
nmhai831-Sep-08 4:19
membernmhai831-Sep-08 4:19 
AnswerRe: question? Pin
Tamer Oz1-Sep-08 8:00
memberTamer Oz1-Sep-08 8:00 
GeneralRe: question? Pin
nmhai831-Sep-08 16:34
membernmhai831-Sep-08 16:34 
GeneralRe: question? Pin
nmhai831-Sep-08 17:07
membernmhai831-Sep-08 17:07 
GeneralRe: question? Pin
Tamer Oz2-Sep-08 3:29
memberTamer Oz2-Sep-08 3:29 
GeneralRe: question? Pin
nmhai832-Sep-08 16:26
membernmhai832-Sep-08 16:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150603.1 | Last Updated 19 Jan 2008
Article Copyright 2008 by Tamer Oz
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid