Click here to Skip to main content
Click here to Skip to main content

Database Export Wizard for ASP.NET and SQL Server

, 20 May 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
A step wizard for ASP.NET to export database objects to CSV, TXT, HTML, XML, or SQL

Table of Contents

Introduction

With this article, I would like to share a simple but useful little tool: ExportWizard, a Step Wizard for Database Export.

It guides users through a few simple steps to choose a database object (table, view, or query), select columns, and export the data in any of the standard formats CSV, HTML, XML, or SQL.

The UI: 3 Simple Steps

The task of exporting from a database can be broken down as follows:

  1. Select a source database object (table, view, or query)
  2. Select columns to include in the export
  3. Select the export format (CSV, HTML, XML, SQL...)

These simple sequential tasks are a good fit for a step wizard.

The implementation discussed in this article is a web control, so the screenshots below are inside a web browser. It could be coded as a desktop application as well with the same basic elements and the same steps arrangement.

Step 1: Choose Data Source

Select table, view or SQL query to export data from.

Step 2: Select Columns to Include

Select columns to include in the export and sorting options.

Step 3: Choose Export Format and Options

This last step is for selecting the export format and options.

Different options for each format (with a little JavaScript to dynamically switch option panel without posting the page):

CSV, TXT, Excel
Options: Header and Separator

XML

Options: Root element, attributes/elements format

HTML
Options: Colors

SQL

Options: Transaction, identity

Using the Web Control

The code is encapsulated as a web control (written in VB.NET) for ASP.NET and SQL Server. It is fully integrated with Visual Studio and its WYSIWYG designer. Just drag & drop to embed the control into your page.

Web Control Properties

Property Description
DesignStep
(Design Time only)
Enables you to get a WYSIWYG display of any step during design time.
DHTMLenabled Determines if user can show and hide options.
HeaderStep1
HeaderStep2
HeaderStep3 

Introductory text for each step. Suggested values:
HeaderStep1 ="Please, select the data source to export."
HeaderStep2 ="Select columns to exports."
HeaderStep3 = "Select Output and format options."

SourceObject Property used to limit the possible tables or views from which to export. Comma-separated list of database objects.
SourceColumns Comma-separated list of columns to be selected by default.
Example: SourceColumns="ID,name,title"
SqlConnection Connection string to the database, for example:
"SERVER=(local);DATABASE=EvoDemo;UID=john;PWD=secret;".
StepIndex
(ReadOnly)

Index of the step currently displayed.

  1. step1_Source
  2. step2_SourceDetails
  3. step3_OutputType
  4. step4_Export

At design time, DesignStep allows users to view each step.

Events

ExportWizard provides one event Show.

Event Description
Show

Triggered on display. Events arguments are the wizard current Title and StepIndex.

ShowEventArgs: Title As String, StepIndex As Integer

Methods

GetExport: Returns the database export as a String.
Example: GetExport("Contact", "Firstname, Lastname, PhoneW, email", "HTML")

Parameter Description
Table

Table or View from which to export.

Columns List of columns to export.
Possible value: Columns="ID,name" or Columns="*"
ExportType

Format in which to export.
Possible values: CSV, HTML, SQL, TXT, or XML.

In addition, standard properties inherited from System.Web.UI.WebControls.WebControl applies.

Embedding the Control into the Page

To embed the control, copy the control DLL into the bin directory of your web application and add two lines of code to your page. The first line registers the control tag prefix (place this at the top of the page):

<%@ Register TagPrefix = "EVOL" Namespace = "Evolutility.ExportWizard" 
	Assembly = "Evolutility.ExportWizard" %> 

The second line embeds the control. Place the line anywhere within the page:

<EVOL:ExportWizard id= "ExportWizard1" runat = "server" 
	SqlConnection = "Server=(local);Database=Demo;Trusted_Connection=yes;" 	 
</EVOL:ExportWizard>

About the Code

Many developers or database administrators have written code to export from a database before (very likely you too if you are reading this article). This web control is written in VB.NET and is not intended to scale, but it does the job with small database tables.

To populate the dropdowns with the list of tables and views, or the list of columns, the technique I used was to query SQL Server system tables directly.

  • sysobjects (contains names of tables, views, stored procedures, and triggers)
  • syscolumns (contains column and stored procedure parameter names)
  • systypes (contains column types as displayed in Enterprise Manager)

The database user must have access to these system tables. These tables can also be used to generate database design documents as discussed in another article.

Notes

This web control is a stand-alone Web control. I have also used a modified version of it (in C#) integrated as a feature of Evolutility CRUD framework available on Get Evolutility at SourceForge.net.

History

  • 19th May, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Olivier Giulieri

United States United States
I'm a UI engineer for a startup in California. What I really enjoy is to build tools to describe UI in metadata, store that metadata (outside of the code) in a database, XML or JSON, and then dynamically generate the UI at run-time based on that metadata... which I do with my open source project Evolutility.
 
My articles on the topic:
Follow on   Twitter   LinkedIn

Comments and Discussions

 
QuestionNew and improved version with preview feature PinmemberOlivier Giulieri23-Sep-14 22:03 
GeneralMy vote of 4 Pinmemberjacksparrow_4725-Aug-13 8:50 
QuestionError PinmemberBinaryMadness5-Aug-13 6:07 
AnswerRe: Error PinmemberNghia Do11-Oct-13 14:19 
QuestionHyperlink when export PinmemberNghiado7731-Jul-13 20:58 
AnswerRe: Hyperlink when export PinmemberOlivier Giulieri5-Aug-13 19:00 
Questiongood article PinmemberMember 1000056625-Jun-13 2:17 
GeneralRe: good article PinmemberOlivier Giulieri5-Aug-13 18:55 
GeneralMy vote of 4 PinmemberAkshay Jani23-Jun-13 22:08 
GeneralRe: My vote of 4 PinmemberOlivier Giulieri5-Aug-13 18:55 
GeneralMy vote of 5 Pinmemberartefakt947-Jun-13 6:41 
GeneralRe: My vote of 5 PinmemberOlivier Giulieri7-Jun-13 17:21 
QuestionNice with small data set Pinmemberstefanveliki23-Apr-13 6:22 
AnswerRe: Nice with small data set PinmemberOlivier Giulieri24-Apr-13 19:27 
AnswerRe: Nice with small data set PinmemberNghia Do11-Oct-13 14:32 
GeneralMy vote of 5 PinmemberPhat (Phillip) H. VU13-Jan-13 22:56 
GeneralRe: My vote of 5 PinmemberOlivier Giulieri14-Jan-13 21:00 
GeneralAbout Article Pinmemberprashant patil 498727-Dec-12 22:49 
GeneralRe: About Article PinmemberOlivier Giulieri29-Dec-12 0:23 
GeneralMy vote of 5 Pinmembercsharpbd20-Nov-12 21:02 
AnswerRe: My vote of 5 PinmemberOlivier Giulieri20-Nov-12 21:20 
GeneralMy vote of 5 PinmentorMd. Marufuzzaman16-May-12 8:12 
GeneralRe: My vote of 5 PinmemberOlivier Giulieri20-Nov-12 21:21 
Thanks.
GeneralRe: My vote of 5 PinmentorMd. Marufuzzaman21-Nov-12 6:00 
QuestionMy 5 PinmemberMarkDaniel5-Jan-12 14:07 

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.141220.1 | Last Updated 20 May 2010
Article Copyright 2010 by Olivier Giulieri
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid