Groups | Blog | Home
all groups > dotnet ado.net > april 2008 >

dotnet ado.net : Saving Data with DataAdapter to Jet DB



NYWGUY54
4/18/2008 5:20:00 PM
I am trying to save changes to a dataset using the dataAdapters update method
to an Access 2003 DB, therefore I'm using an OleDbDataAdapter to accomplish
this.
I am using a For/Next loop to change a single column of data in the
dataTable, & I know this works. The problem arises when I try to write the
changes to the Access DB, nothing happens but the code process properly. I
use virtually the same code set in another project writing to a SQL server DB
& that works just fine. Is there some issue with OLEDB & Jet that this does
not work or that i must do something different?
Just for laughs I included a code snipit of what i'm doing.

Try
Conn.Open()
daVoters.Update(dsCommittee, "Voters")
Conn.Close()
dsCommittee.AcceptChanges()
Catch ex As OleDb.OleDbException
Conn.Close()
MessageBox.Show("There was an error updating the Database" &
vbCr & vbLf & ex.Message, "Prep Data", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try

BTW I can do this by writing each change to the DB as I change it in the
datatable, but this requires me to open & close the connection nearly 1/2
million times (there are over400,000 records in the DB)

Thanks
Gary

Scott M.
4/19/2008 9:25:06 AM
Cor, look at his supplied code. He is calling AcceptChanges after he uses
the Update method of the DataAdapter, not before, as you talk about.

-Scott

[quoted text, click to view]

William Vaughn [MVP]
4/19/2008 9:33:20 AM
Consider that when you write to a JET database, the data is NOT written to
the database--at least not immediately. Changes are saved to a local cache
and when the engine goes into an idle state, the changes are posted to the
file. I would let the application rest for awhile after writing. Another
approach is to encapsulate the operations in a transaction. This reduces
performance (as the engine writes each change and keeps a rollback state)
but it seems to work. Of course, that's assuming I would use JET at all...
which I wouldn't. I would first consider SQL Compact or some DBMS engine
that I can encrypt.

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
[quoted text, click to view]
Cor Ligthert[MVP]
4/19/2008 2:00:01 PM
Hi,

About 100000000000000000000 times (or probably more) is written in this
newsgroup not to use the Acceptchanges before you do an update.

The Acceptchanges accept all the changes in the DataSet as done, so there is
nothing anymore to update.
As it is about a complete dataTable or DataSet, then the DataAdapter has an
inbuild AcceptChanges as soon as the update is done.

Cor


"NYWGUY54" <NYWGUY54@discussions.microsoft.com> schreef in bericht
news:92E3B536-5A3C-4CEE-9605-AF25BCF8485F@microsoft.com...
[quoted text, click to view]
Cor Ligthert[MVP]
4/21/2008 5:22:08 AM
Scott

You are right , and you won't believe this, I have checked this more than
one time,
Probably the way the code showed up here,

Thanks for the correction.

Cor

"Scott M." <smar@nospam.nospam> schreef in bericht
news:%23nxNuBioIHA.4308@TK2MSFTNGP06.phx.gbl...
[quoted text, click to view]
Cor Ligthert[MVP]
4/21/2008 5:24:07 AM
Hi,

Sorry for my misread,

Did you investigate your connection string or maybe your SQL transact code,
be aware that SQL for OleDB is not always the same as for SQL server.

Cor

"NYWGUY54" <NYWGUY54@discussions.microsoft.com> schreef in bericht
news:92E3B536-5A3C-4CEE-9605-AF25BCF8485F@microsoft.com...
[quoted text, click to view]
NYWGUY54
4/21/2008 6:36:00 AM
Thanks everyone,
I finally figured out what i had wrong. My code (sample) does work when I
add this before it :
Dim cb_voters As OleDbCommandBuilder = New OleDbCommandBuilder(daVoters)
This will build a default update command. I instantiate all my dataadapters
in code (not as objects) & forgot to assign an updatecommand. The odd thing
is when I wrote another piece of code to test this the debugger threw an
error that told me I needed an update command, my primary code didn't through
the error, just processed it and moved on & that is what confounded me.
William, as far as the DB goes, you are correct I don't want to use Jet
either, but this has to be both low cost & very portable. But if you know of
another DB that i can simple copy from machine to machine (with no install)
that would perform better than Jet (Access), I'll gladly take your advice.
Thanks
Gary

[quoted text, click to view]
William Vaughn [MVP]
4/21/2008 6:47:45 PM
The SQL Server Compact .SDF database is small, fast and light, requires no
"install" (there are 6 or so DLLs that can be attached to the project) and
can be passed around just like a JET database. It's also free. See my EBook
at www.hitchhikerguides.net.


--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
[quoted text, click to view]
AddThis Social Bookmark Button