473,395 Members | 1,440 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Sync problem -- database getting updated, but _not_ DataSet??


I'm using an in-core DataSet as an image of my application's
'database' (a multi-table Access97 mdb file). Updates are made to
the DataTables within the DataSet via forms with bound TextBoxes,
then written to the database... or at least that's what's supposed
to be happening.

Unfortunately, I've discovered that while it appears that when I
create a new record/row I'm successfully updating the Access
database, once the Update is complete the new record is not (is no
longer) present in the DataSet's DataTable. Ack!

It's not what we don't know that gives us trouble, it's what
we know that ain't so. -- Will Rogers

While it's _possible_ that I've invented the dotNET equivalent of
transporter technology and my DataSet is merely acting as a tachyon
sequencing buffer during the database updates, it's slightly more
likely that I'm missing some subtle (or not-so-subtle) part of the
dotNet DataSet-to-database sequence.

Here's what I'm doing under the impression that it's supposed to be
updating both the DataTable/DataSet AND the database.

Given a DataSet 'ds' and a table within that DataSet whose name is
contained in the variable 'table_name', the logic looks like:
---------
if ( ds.HasChanges() ) {
// (Odd if it doesn't)
DataTable dt_changes = ds[table_name].GetChanges();

// Make changes, but only if any exist
if (dt_changes != null) {
DataRowCollection drc = dt_changes.Rows; //**DEBUG**
if (dt_changes.Rows.Count > 0) {
try {
// Write changes back to database (.mdb file)
DbAdapters[table_name].Update(dt_changes);
} catch (DBConcurrencyException DBCe) {
ShowDbConcurrencyException(DBCe); // Report error
}
// Make changes permanent part of DataSet
ds.Tables[table_name].AcceptChanges();
}
}
}
---------

The data does get to the database file... it's just not visible to
either a DataView of the table or a VSDebug Watch of the DataTable
itself (as far as I can tell -- 'Watch'ing a DataTable with 150
items gets a little tricky <grin>)
Assuming that neither the OleDbDataAdapter.Update() nor the
DataTable.AcceptChanges() triggers an exception, _should_ the above
do what I think it should, that is, update both the in-core
DataTable AND the Access97 database? Or is there something subtle
I'm overlooking?

Or do I truly need to re-.Fill each table from the database every
time I issue an Update() to it? (Ack! Phlblbt!)
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)
--
You can start a fire just by rubbing two dry theories together.
-- Robert M. Powers, British astronomer
--
Aug 22 '05 #1
4 2594
Frank,

I think your problem lies with these statements:

DataTable dt_changes = ds[table_name].GetChanges();

- and -

DbAdapters[table_name].Update(dt_changes);

This would be ok to do if you were basically "rolling your own" update
stuff, but in using the .Update() method of the DataAdapter, I believe you
need to use the original DataSet or DataTable and not use the .GetChanges()
method.

~~Bonnie

Aug 22 '05 #2
Bonnie,

Thank you for taking the time to reply.

On Mon, 22 Aug 2005 11:21:03 -0700, Bonnie Berent [C# MVP] <Bo**************@discussions.microsoft.com> wrote:
I think your problem lies with these statements:

DataTable dt_changes = ds[table_name].GetChanges();

- and -

DbAdapters[table_name].Update(dt_changes);

This would be ok to do if you were basically "rolling your own" update
stuff, but in using the .Update() method of the DataAdapter, I believe you
need to use the original DataSet or DataTable and not use the .GetChanges()
method.


Oh. So if someone is using DataAdapter.Update() they'd have to re-write
the entire table? That's doable-but-not-efficient in my case, but for a
really large table I'd think it could approach "horrendous". Ig.

Anyway, it's certainly something I hadn't considered. I guess I'd better
re-read the OleDbDataAdapter.Update() documentation again.

Thanks for pointing that out to me. I'll let you know what happens.
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)
Aug 22 '05 #3
No no no ... it doesn't re-write the entire table. But the .Update() method
needs to have a before-and-after snapshot of the data (hence the whole
DataSet) in order to both update the database correctly (IOW, to know if
you're doing an Update, an Insert or a Delete) and to do the proper thing to
the DataSet when it's done.

~~Bonnie

"Frnak McKenney" wrote:
Bonnie,

Thank you for taking the time to reply.

On Mon, 22 Aug 2005 11:21:03 -0700, Bonnie Berent [C# MVP] <Bo**************@discussions.microsoft.com> wrote:
I think your problem lies with these statements:

DataTable dt_changes = ds[table_name].GetChanges();

- and -

DbAdapters[table_name].Update(dt_changes);

This would be ok to do if you were basically "rolling your own" update
stuff, but in using the .Update() method of the DataAdapter, I believe you
need to use the original DataSet or DataTable and not use the .GetChanges()
method.


Oh. So if someone is using DataAdapter.Update() they'd have to re-write
the entire table? That's doable-but-not-efficient in my case, but for a
really large table I'd think it could approach "horrendous". Ig.

Anyway, it's certainly something I hadn't considered. I guess I'd better
re-read the OleDbDataAdapter.Update() documentation again.

Thanks for pointing that out to me. I'll let you know what happens.
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)

Aug 22 '05 #4
Bonnie - he's actually doing this part right. He's using the GetChanges to
update the data but he's calling AcceptChanges on the original dataset.
That will cause the state of the datatable to be the same as if he had used
Update on it directly. But I still can't figure out his problem ;-(..

"Bonnie Berent [C# MVP]" <Bo**************@discussions.microsoft.com> wrote
in message news:CD**********************************@microsof t.com...
No no no ... it doesn't re-write the entire table. But the .Update()
method
needs to have a before-and-after snapshot of the data (hence the whole
DataSet) in order to both update the database correctly (IOW, to know if
you're doing an Update, an Insert or a Delete) and to do the proper thing
to
the DataSet when it's done.

~~Bonnie

"Frnak McKenney" wrote:
Bonnie,

Thank you for taking the time to reply.

On Mon, 22 Aug 2005 11:21:03 -0700, Bonnie Berent [C# MVP]
<Bo**************@discussions.microsoft.com> wrote:
> I think your problem lies with these statements:
>
> DataTable dt_changes = ds[table_name].GetChanges();
>
> - and -
>
> DbAdapters[table_name].Update(dt_changes);
>
> This would be ok to do if you were basically "rolling your own" update
> stuff, but in using the .Update() method of the DataAdapter, I believe
> you
> need to use the original DataSet or DataTable and not use the
> .GetChanges()
> method.


Oh. So if someone is using DataAdapter.Update() they'd have to re-write
the entire table? That's doable-but-not-efficient in my case, but for a
really large table I'd think it could approach "horrendous". Ig.

Anyway, it's certainly something I hadn't considered. I guess I'd better
re-read the OleDbDataAdapter.Update() documentation again.

Thanks for pointing that out to me. I'll let you know what happens.
Frank McKenney, McKenney Associates
Richmond, Virginia / (804) 320-4887
Munged E-mail: frank uscore mckenney ayut minds pring dawt cahm (y'all)

Aug 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Pierluigi Terzoli | last post by:
Hi everybody, I need help for this problem: I'm using a DataGrid to Insert/Modify/Cancel data from a single table. At the moment, every cell modification of a pre-existing row is correctly update...
5
by: Karl | last post by:
Hi C# experts, I am to C# and .NET. I am writing a database application using C# and Dataset. In Sql server, I have a Acount table which contains over 100,000 records. This table will be...
1
by: pStan | last post by:
Nubie Question...I'm sure this is simple, but here goes anyway. I have a small VB.Net application that uses a local Access Database. I want that same local data replicated to an Internet web site...
4
by: Frnak McKenney | last post by:
I'm using an in-core DataSet as an image of my application's 'database' (a multi-table Access97 mdb file). Updates are made to the DataTables within the DataSet via forms with bound TextBoxes,...
8
by: morleyc | last post by:
Hi, until recently i was quite happy to add data sources from mssql database in visual studio and drag the datasets directly onto the form this creating a directly editable form which worked well....
0
by: =?Utf-8?B?Sm9uIEdvbnphbGVz?= | last post by:
Is it possible in .Net Framework to query only the updated entries in AD? I'm trying to have sync process with AD, and considering the large number contains on it. I would look to getting only the...
0
by: John Sheppard | last post by:
Hello there, How do people normally sync datasets between client and webservice? For example; I send a dataset to the webservices with updated rows on it, the webservice execute the sql to...
9
by: Peter Duniho | last post by:
Is there a straightfoward API in .NET that allows for inspection of a database? That is, to look at the structure of the database, without knowing anything in advance about it? For example,...
0
MrMancunian
by: MrMancunian | last post by:
How to create a database connection without using wizards Introduction I've seen a lot of questions on the net about getting data from, and saving data to databases. Here's a little insight how...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.