TheUndecider
asked on
Export Datatable Records to MS Access Database
Hello, I have a datatable that is populated from a SQL 2000 stored procedure. I basically select * from mytable. What I need to do is to export or copy these records into an MS Access database. I don't need to edit any of the data. I only need to 'bulk export.' I am not supposed to use a DTS package though. Both the SQL table and the Access table have the same fields.
I'm trying to take another route in order to not use the datatable and try to copy the records from the SQL table into the Access table. This is what I am trying to do, but I get an exception error:
Dim ADOConn As New System.Data.OleDb.OleDbCon nection("P rovider= Microsoft.Jet.OLEDB.4.0;Da ta Source= c:\MyAccessDB.mdb;")
Dim SQLString As String
ADOConn.Open()
SQLString = "INSERT INTO MY_Export SELECT * FROM MY_Export IN Server=MyServer;database=M yDatabase; User ID=MyUser;Pwd=MyPassword;P ersist Security Info=True;Integrated Security=sspi;"
Dim AccessCommand As New System.Data.OleDb.OleDbCom mand(SQLSt ring, ADOConn)
AccessCommand.ExecuteNonQu ery()
ADOConn.Close()
Do you have an idea on what I am doing wrong or should I abandon this altogether and try to use the datatable, loop through all the records there and try to export them to Access. If so, can anyone give me an example on how to acomplish this?
Thanks!
I'm trying to take another route in order to not use the datatable and try to copy the records from the SQL table into the Access table. This is what I am trying to do, but I get an exception error:
Dim ADOConn As New System.Data.OleDb.OleDbCon
Dim SQLString As String
ADOConn.Open()
SQLString = "INSERT INTO MY_Export SELECT * FROM MY_Export IN Server=MyServer;database=M
Dim AccessCommand As New System.Data.OleDb.OleDbCom
AccessCommand.ExecuteNonQu
ADOConn.Close()
Do you have an idea on what I am doing wrong or should I abandon this altogether and try to use the datatable, loop through all the records there and try to export them to Access. If so, can anyone give me an example on how to acomplish this?
Thanks!
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Try first: delete the table and try your code
If not successful try if this works...
Dim myConn as string="your SQL connection string"
Dim vSQL as string ="SELECT MY_Export.* INTO MY_Export IN ' C:\MyAccessDB.mdb' FROM MY_Export"
if RunMySQL(vSQL,myConn)
'ok
else
'failed
end if
Open in new window