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";
extendedDt.ToWord(@"C:\Friends.docx");
extendedDt.ToExcel(@"C:\Friends.xlsx");
MessageBox.Show(extendedDt.ToHTML());
extendedDt.MailProperties.SmtpClient.Host = "localhost";
extendedDt.SendMail("oztamer@hotmail.com", "oztamer@hotmail.com", "Friends");
extendedDt.PrintProperties.PrintDocument.DefaultPageSettings.Landscape = true;
extendedDt.Print();
extendedDt.DataProperties.Connection.ConnectionString =
"data source=.;initial catalog=dummy;integrated security=SSPI";
extendedDt.DataProperties.Command.CommandText = "SELECT * FROM Dummy";
extendedDt.Fill();
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.