ExtendedDataTable
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 objectToExcel
: Exports the data as Excel worksheet in client's computerToHtml
: Generates the HTML code usingtable
,tr
,td
tags that represent dataSendMail
: Allows users to send the HTML table that represents data as emailPrint
: Prints the data to any printerFill
: Easily fills table with data from database with theDataAdapter
component it includesUpdate
: Allows users to easily update data to database withDataAdapter
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 forConnection
,Command
,DataAdapter
components to fill or update data.
Let me explain the technology that is used to provide these functionalities:
ToWord
andToExcel
methods Office Interop is used to create and fill the documents.ToHtml
is a simple method that generates the HTML code usingtr
,td
,table
tags by iterating through rows and columns.SendMail
creates aMailMessage
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 likeMeasureString
,DrawRectangle
,FillRectangle
andDrawString
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
andUpdate
methods usesdataadapter
toselect
,insert
andupdate
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.