Transfer Data from Sql Server to Access table

C

Cyrille Armand

Hi

Help a newbie!!!

I am trying to copy the content of a datatable (dt) into an Access table. It
seems the datatable has the data I want, and when I execute the code below it
doesn't generate errors, my only problem is that it doesn't work. Once I open
my Access db, the table is still empty. What gives?


Dim oleDa As OleDbDataAdapter = New OleDbDataAdapter("Select
* fom " + Table.Name, cnn.ConnectionString)
Dim Ocmd As OleDbCommandBuilder = New
OleDbCommandBuilder(oleDa)

oleDa.AcceptChangesDuringFill = False
oleDa.Fill(dt)
oleDa.Update(dt)
oleDa.Dispose()
 
W

W.G. Ryan

Cyrille:

You are using one adapter to Fill thetable and the same adapter to try to
update it. It looks like it's just going to populate the source table.
You'll need a different adapter for the destination table. Actually, now
that I look at it, i see why it's not throwing an error. You can pulling
from an empty table in all likelihood, so there are no rows. If you check
the Rows.count property of dt, right before you call Update, how many rows
are there?

The end problem though is that you'll need a different adapter or you'll
have to reconfigure your adatper if you want to move the data to a different
table. calling fill, then update on the same one will just yeild in the
same rows (assuming there are rows) b/c your source and destination tables
are the same unless there's other code I'm not seeing here. Typically, you
fill from one table (the acceptchangesduringfill is correct) but you use a
second adapter to call Update on, passing in the same datatable you filled
with the first Adapter.

Does that make sense?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top