none
How can I copy data from table to tabel using C# RRS feed

  • Question

  •  

    How can I copy data from table in access database to another table have the same stricture in another database access in c#

    Monday, May 5, 2008 9:25 AM

Answers

  • I don't have a C# example but this should be relatively easy to convert:

    Code Snippet

            Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                                                "Data Source=C:\Test Files\db10.mdb")

            AccessConn.Open()

            Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [Data] SELECT * FROM [MS Access;DATABASE=C:\Test Files\db1 XP.mdb;].[Data]", AccessConn)
            AccessCommand.ExecuteNonQuery()
            AccessConn.Close()



    Wednesday, May 7, 2008 12:19 PM

All replies

  • Hi,

    You could go about this in a number of different ways. The two easiest (imho):

    1. Retrieve all information from the first table, store it in memory in a DataTable or an object, and write it to the second table.
    2. Use an Access query (a 'stored procedure') which you call from C# using a OleDbCommand.

    The second method is by far the easiest. Access can assist you in writing a 'stored procedure' to copy data. Calling it is as easy as connecting to the database, creating an OleDbCommand, set the commantext to the name of the 'stored procedure', settting the commandtype to stored procedure and calling ExecuteNonQuery.

    Hope this helps.

    • Proposed as answer by Chethiya Monday, August 20, 2018 4:34 PM
    • Unproposed as answer by Chethiya Monday, August 20, 2018 4:34 PM
    Monday, May 5, 2008 9:48 AM
  • I don't have a C# example but this should be relatively easy to convert:

    Code Snippet

            Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & _
                                                                "Data Source=C:\Test Files\db10.mdb")

            AccessConn.Open()

            Dim AccessCommand As New System.Data.OleDb.OleDbCommand("INSERT INTO [Data] SELECT * FROM [MS Access;DATABASE=C:\Test Files\db1 XP.mdb;].[Data]", AccessConn)
            AccessCommand.ExecuteNonQuery()
            AccessConn.Close()



    Wednesday, May 7, 2008 12:19 PM