Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server

Table Data Exporter

4.58/5 (7 votes)
24 Jan 2008CPOL 1   314  
The Table Data Exporter creates a SQL script for data in a table.

ExportTable

Introduction

This application will let you script table data into a file. It will create an INSERT statement for each row in your table.

Using the code

The application is written in Visual Studio 2003, and has been tested with SQL Server only. Potentially, the application can work with other databases.

The application uses the DataLink object to connect to the database:

VB
Protected Function EditConnectionString(ByVal sConnectionString As String)
    Try
        Dim oDataLinks As Object = CreateObject("DataLinks")
        Dim cn As Object = CreateObject("ADODB.Connection")
        cn.ConnectionString = sConnectionString
        oDataLinks.hWnd = Me.Handle

        If Not oDataLinks.PromptEdit(cn) Then
            'User pressed cancel button
            Return ""
        End If

        cn.Open()
        Return cn.ConnectionString
    Catch ex As Exception
        MsgBox(ex.Message)
        Return ""
    End Try
End Function

License

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