Monday, March 12, 2012

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

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.
--
Message posted via DotNetMonster.com
http://www.dotnetmonster.com/Uwe/Forums.aspx/dotnet-ado-net/200511/1On Fri, 18 Nov 2005 16:54:31 GMT, "Jon S via DotNetMonster.com" <u2272@.uwe> wrote:
¤ 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)

Labels: , , , , , , , , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home