Click here to Skip to main content
15,902,492 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,
i want to export my msaccess tables to desktop on click of the button using "insert into openrowset"
i m getting error in "INSERT INTO" statement

please someone help me with this.
Here is my code:


VB
Public Class XtraForm3

    Private Sub SimpleButton1_Click(sender As System.Object, e As System.EventArgs) Handles SimpleButton1.Click
        Dim folderbrowserdialog1 As New FolderBrowserDialog
        'folderbrowserdialog1.ShowDialog()
        'If folderbrowserdialog1.ShowDialog() = DialogResult.OK Then
        '    MessageBox.Show(folderbrowserdialog1.SelectedPath)
        'End If
        If (folderbrowserdialog1.ShowDialog() = DialogResult.OK) Then
            TextEdit1.Text = folderbrowserdialog1.SelectedPath
        End If

        InsertData()
    End Sub

    Private Sub InsertData()
        Dim queryString As String = "INSERT INTO OPENROWSET ('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DMT.net\mdb\Edata2.mdb;', 'SELECT * FROM ArtBez')"

        Dim conn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\DMT.net\mdb\Edata2.mdb")

        Dim cmd As New System.Data.OleDb.OleDbCommand(queryString, conn)
        conn.Open()
        cmd.CommandType = CommandType.Text
        Dim adapter As New System.Data.OleDb.OleDbDataAdapter(cmd)
        cmd.ExecuteNonQuery()
        conn.Close()

    End Sub
End Class
Posted
Updated 27-Dec-13 1:14am
v3
Comments
Maciej Los 30-Dec-13 3:59am    
What you mean: "export my msaccess tables to desktop"? What are you trying to achieve? I don't understand you...
Please, be more specific and provide more details, clarify your question.

1 solution

Please, read my comment to the question first!

If you want to copy ms access database file from one location into another, please use File.Copy()[^] method.

If you would like to copy data between existing databases, you need to connect to destination database (for example: C:\DMT.net\mdb\Edata2.mdb) and use sql command like that:
SQL
INSERT INTO DestinationTableName (Field1, Field2, Field3,..., FieldN)
SELECT Field1, Field2, Field3,..., FieldN
FROM SourceTableName IN 'C:\DMT.net\mdb\Edata1.mdb'

Note: In a destination database destination table must exists!

For further information, please see:
IN Clause - MS Access[^]
Accessing external data using the IN clause[^]

But if you would like to copy data into new (empty) database, you need to:
  1. create it first[^]
  2. copy data as is shown above using make table query[^]



More:
Tips and Techniques for Queries in Access 2007[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900