rockas1982
asked on
COPY TABLE1 FROM C:\DB1.MDB TO C:\DB2.MDB
i have 2 db same structre and i want to copy the data of table1 from db1 to db2
but i dont want to include the first field(key field and dont care about it)
i have done this in vb.net
Private Sub UpdateData(ByVal SelSql As String)
Dim sourceSQL As String = SelSql
Dim targetSQL As String = SelSql
Dim targetDA As New OleDbDataAdapter(targetSQL , CON1)
Dim cb As New OleDbCommandBuilder(target DA)
Dim targetCommand As OleDbCommand = cb.GetInsertCommand
Dim cmdText As String = targetCommand.CommandText
If CON2.State = Data.ConnectionState.Close d Then CON2.Open()
If targetCommand.Connection.S tate = Data.ConnectionState.Close d Then targetCommand.Connection.O pen()
cmdText = cmdText.Replace("( ", "( [")
cmdText = cmdText.Replace(" , ", "] , [")
cmdText = cmdText.Replace(" )", "] )")
cmdText = cmdText.Replace("[?]", "?")
targetCommand.CommandText = cmdText
Dim sourceCommand As New OleDbCommand(sourceSQL, CON2)
Dim sourceReader As OleDbDataReader
sourceReader = sourceCommand.ExecuteReade r()
Me.Text = 0
While sourceReader.Read()
For i As Integer = 1 To sourceReader.FieldCount - 1
targetCommand.Parameters(i - 1).Value = sourceReader(i)
Next
targetCommand.ExecuteNonQu ery()
Me.Text = Me.Text + 1
End While
sourceReader.Close()
CON2.Close()
targetCommand.Connection.C lose()
End Sub
https://www.experts-exchange.com/questions/21975556/copy-database-data-from-one-database-to-onother-same-structure.html
this works but is there any better way this takes to much time
Dimitris
but i dont want to include the first field(key field and dont care about it)
i have done this in vb.net
Private Sub UpdateData(ByVal SelSql As String)
Dim sourceSQL As String = SelSql
Dim targetSQL As String = SelSql
Dim targetDA As New OleDbDataAdapter(targetSQL
Dim cb As New OleDbCommandBuilder(target
Dim targetCommand As OleDbCommand = cb.GetInsertCommand
Dim cmdText As String = targetCommand.CommandText
If CON2.State = Data.ConnectionState.Close
If targetCommand.Connection.S
cmdText = cmdText.Replace("( ", "( [")
cmdText = cmdText.Replace(" , ", "] , [")
cmdText = cmdText.Replace(" )", "] )")
cmdText = cmdText.Replace("[?]", "?")
targetCommand.CommandText = cmdText
Dim sourceCommand As New OleDbCommand(sourceSQL, CON2)
Dim sourceReader As OleDbDataReader
sourceReader = sourceCommand.ExecuteReade
Me.Text = 0
While sourceReader.Read()
For i As Integer = 1 To sourceReader.FieldCount - 1
targetCommand.Parameters(i
Next
targetCommand.ExecuteNonQu
Me.Text = Me.Text + 1
End While
sourceReader.Close()
CON2.Close()
targetCommand.Connection.C
End Sub
https://www.experts-exchange.com/questions/21975556/copy-database-data-from-one-database-to-onother-same-structure.html
this works but is there any better way this takes to much time
Dimitris
If you only need to copy the data once, you could export it to a flat file (e.g. CSV), then bulk import the flat file into the other DB.
Code looks something like this:
Using conn as New OleDbConnection(connection String)
Dim sql as String = "SELECT <fieldList> INTO <destinationTable> FROM <sourceTables>"
Using cmd as New OleDbCommand(sql,conn)
conn.Open
cmd.ExecuteNonQuery
End Using
End Using
Using conn as New OleDbConnection(connection
Dim sql as String = "SELECT <fieldList> INTO <destinationTable> FROM <sourceTables>"
Using cmd as New OleDbCommand(sql,conn)
conn.Open
cmd.ExecuteNonQuery
End Using
End Using
ASKER
thnx for fast replay
i'm using access 2003 with vb.net 2003
i'm new in sql commands and i saw something that might work the "IN" command .. can this help me ?
the sample i saw is this
strSQL = "INSERT INTO Pricebook SELECT * FROM Pricebook IN 'K:\PriceBk\PriceBook.mdb' "
i want to give the filepathh from vb.net sourcefile and targetfile
Can i connect to my target database and make an insert query asking data from onother database "insert into table1 (all fileds except the first) select table1 (all fileds except the first) IN (filepathAndName) (where shop = "shop1")
do tou think this may work
P.S. is there any way i can add progressbar into this so user can see how long this will take(not important)
sorry for my english(Greece)
DIMITRIS
i'm using access 2003 with vb.net 2003
i'm new in sql commands and i saw something that might work the "IN" command .. can this help me ?
the sample i saw is this
strSQL = "INSERT INTO Pricebook SELECT * FROM Pricebook IN 'K:\PriceBk\PriceBook.mdb'
i want to give the filepathh from vb.net sourcefile and targetfile
Can i connect to my target database and make an insert query asking data from onother database "insert into table1 (all fileds except the first) select table1 (all fileds except the first) IN (filepathAndName) (where shop = "shop1")
do tou think this may work
P.S. is there any way i can add progressbar into this so user can see how long this will take(not important)
sorry for my english(Greece)
DIMITRIS
Chaosian
Hi Jeff ;-). Long time no speak.
Can you do that from one DB to another? Won't you need two different connections?
Roger
Hi Jeff ;-). Long time no speak.
Can you do that from one DB to another? Won't you need two different connections?
Roger
ASKER
I hoped that sql will call the second database with the "IN" command ... don't really know
Roger...
Shoot... you almost caught me...
The sneaky here is that with an enterprise level database (read SQL Server), you can use fully-qualified table names to work across multiple registered databases. I missed the MDB part.
Dimitri... let me post a pointer for you....the Acces gurus can probably help out on this one...
Shoot... you almost caught me...
The sneaky here is that with an enterprise level database (read SQL Server), you can use fully-qualified table names to work across multiple registered databases. I missed the MDB part.
Dimitri... let me post a pointer for you....the Acces gurus can probably help out on this one...
Dimitri.... I'll do one better....
Create the query in Access using the query builder. Click the button in the upper left until it says "SQL"... cut-and-paste this into your VB app as the SQL statement for your command (fixing any quotes, as required)
This way, you can test the SQL statement to make sure it does what you want... and the make-table wizard lets you specify the other database to use.
Create the query in Access using the query builder. Click the button in the upper left until it says "SQL"... cut-and-paste this into your VB app as the SQL statement for your command (fixing any quotes, as required)
This way, you can test the SQL statement to make sure it does what you want... and the make-table wizard lets you specify the other database to use.
Yup.
Looks like you're already along the right lines.
You just have to specify the fields you do want (to eliminate the fields you don't).
strSQL = "INSERT INTO Pricebook (Field2, Field3, Field26) SELECT Field2, Field3, Field26 FROM Pricebook IN 'K:\PriceBk\PriceBook.mdb' "
or
strSQL = "INSERT INTO Pricebook (Field2, Field3, Field26) SELECT Field2, Field3, Field26 FROM [K:\PriceBk\PriceBook.mdb] .Pricebook "
Not dissimilar to using a linked server - considering that mdb's are file based - you just specify the file.
Executed with a connection to the db you want to receive the records of course.
Looks like you're already along the right lines.
You just have to specify the fields you do want (to eliminate the fields you don't).
strSQL = "INSERT INTO Pricebook (Field2, Field3, Field26) SELECT Field2, Field3, Field26 FROM Pricebook IN 'K:\PriceBk\PriceBook.mdb'
or
strSQL = "INSERT INTO Pricebook (Field2, Field3, Field26) SELECT Field2, Field3, Field26 FROM [K:\PriceBk\PriceBook.mdb]
Not dissimilar to using a linked server - considering that mdb's are file based - you just specify the file.
Executed with a connection to the db you want to receive the records of course.
basic ssyntax is
Select * into tablename in '\path\database.mdb' from tablename
Select * into tablename in '\path\database.mdb' from tablename
isn't insert into an append?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What database are you targeting?