How to copy an Access database using ADO.NET and C#???

  • Thread starter Thread starter Jon S via DotNetMonster.com
  • Start date Start date
J

Jon S via DotNetMonster.com

Hi all,

I have an Access '97 database called "dbHLS", inside this database I have a
table called "tbHLS". I would like to copy the table tbHLS from within the
dbHLS.mdb to an Access 2002 database called "dbTarget". Obviously as I'm
copying the table tbHLS I dont want anything to do with the table to change
other than the location of it.

Can this be done? if so how can it be done?? Anyone know of any links???

Thanks in advance.
 
¤ Hi all,
¤
¤ I have an Access '97 database called "dbHLS", inside this database I have a
¤ table called "tbHLS". I would like to copy the table tbHLS from within the
¤ dbHLS.mdb to an Access 2002 database called "dbTarget". Obviously as I'm
¤ copying the table tbHLS I dont want anything to do with the table to change
¤ other than the location of it.
¤
¤ Can this be done? if so how can it be done?? Anyone know of any links???

The following code will create the table and copy the data. However, it will not create any indexes
or primary keys, etc.

Function ExportAccessToAccess() As Boolean

Dim AccessConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;"
& _
"Data Source=e:\My Documents\dbHLS.mdb")

AccessConn.Open()

Dim AccessCommand As New System.Data.OleDb.OleDbCommand("SELECT * INTO [MS
Access;DATABASE=E:\My Documents\dbTarget.mdb;].[tbHLS] FROM tbHLS", AccessConn)

AccessCommand.ExecuteNonQuery()
AccessConn.Close()


Paul
~~~~
Microsoft MVP (Visual Basic)
 
Back
Top