Introduction

This article introduces how to export data from database to Excel, PDF, MS Word, HTML, MS clipboard ,XML, DBF, SQL Script, SYLK, DIF, CSV without Automation and Acrobat Reader.

Background

For a programmer, in order to export data to a file specified, you don't need to write a plenty of code, you just need to choose a datasource or write a command to select data and specify a file format to show the data.

Four simple steps:

  1. Select a database.(SQL Client, OLE DB)
  2. Select data source from the database.(Table, View and SQL Command)
  3. Select columns as you want to export.
  4. Specify a file format to show the result and save it to a file with the specified format.( XLS, PDF, MS Word, HTML, MS clipboard ,XML, DBF, SQL Script, SYLK, DIF, CSV)

Here, we use step wizard to show you how to do it.

Step 1: Select a database

You may choose a database to export data from. The database may be SQL Client or OLE DB and so on. Then you may create a connection to the database by inputting the connection string.

choose_database.png

Step 2: Select data source from the database

Choose data source from the database. It may be a table, a view or SQL Command. Here we list two styles.

Data source from table:

choose_datasource.png

Data source from SQL Command:

choose_datasource2.png

Step 3: Select columns

After selecting a Table, View or SQL Command, it will display all columns of it. If you don’t need all of the data in it, you may select columns of it. Just choose some of them you need.

choose_columns.png

Step 4: Specify a file format and Save

The last step is to show your data result with a specified file format. In the component, many formats are supported, such as XLS, PDF, MS Word, HTML, MS clipboard, XML and so on. And you may give a path to save the file.

choose_result_format.png

Use the Component

Parameter Value
Database Choose one or add one unlisted
Data source Table, View or SQL Command
Columns Select columns to export
Export format Possible values:
XLS, PDF, MS Word, HTML, MS clipboard, XML and so on
Save path Select a local path

Supported Database

If we have a database-provider, DataExportWizard could support any database. Editing the App.config file can add other database providers. All installed providers that implement System.Data.Common.DbProviderFactory will be automatically filled in the Database-Provider list of the first step.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.data>
    <DbProviderFactories>
      <add name="SqlClient Data Provider"
       invariant="System.Data.SqlClient"
       description=".Net Framework Data Provider for SqlServer"
       type="System.Data.SqlClient.SqlClientFactory, System.Data, 
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
      <add name="OLE DB Data Provider"
       invariant="System.Data.OleDb"
       description=".Net Framework Data Provider for OLE DB"
       type="System.Data.OleDb.OleDbFactory, System.Data, 
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </DbProviderFactories>
  </system.data>
</configuration>

Conclusion

In this method, we use a free data export component. You may download it here.

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架
新浪微博粉丝精灵,刷粉丝、刷评论、刷转发、企业商家微博营销必备工具"