473,670 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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) {
DataRowCollecti on drc = dt_changes.Rows ; //**DEBUG**
if (dt_changes.Row s.Count > 0) {
try {
// Write changes back to database (.mdb file)
DbAdapters[table_name].Update(dt_chan ges);
} catch (DBConcurrencyE xception DBCe) {
ShowDbConcurren cyException(DBC e); // 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 OleDbDataAdapte r.Update() nor the
DataTable.Accep tChanges() 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 2615
Frank,

I think your problem lies with these statements:

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

- and -

DbAdapters[table_name].Update(dt_chan ges);

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_chan ges);

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.Upd ate() 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 OleDbDataAdapte r.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_chan ges);

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.Upd ate() 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 OleDbDataAdapte r.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******** *************** ***********@mic rosoft.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_chan ges);
>
> 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.Upd ate() 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 OleDbDataAdapte r.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
2691
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 on the DB. I have some doubts about inserting a new row. The table has a Id field that is a primary key defined ad Identity properties on SQLServer engine. This column isn't visible on the grid and a properties DefaultValue=0 is defined.
5
14764
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 accessed and updated by many users at same time. So the data in this table keeps changing and growning. I want to keep each user's local Dataset updated every time he does a update or does a query. My code is like this:
1
2058
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 so that I can use an ASP.NET page to work with the data. My DB and Application is not really big enough to mess with SQL server... QUESTION: What is the best way to sync my data to the web. I've tried the built in replication in Access and...
4
295
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, 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...
8
4124
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. However i have recently started a project which will require synchronization to a remote database. Also the underlying database provider may change at a later date. From what i have read it seems that a layered approach is necessary, or at...
0
905
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 updated entries to sync. I appreciate you help. Thanks!
0
1104
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 persist it to the database and updates the dataset so that haschanges=false and with the correct Ids in it, I now have an updated dataset on the webservice, do I just pass that back to the client and merge it?
9
2332
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, retrieving a list of tables in the database. Doing a little browsing in MSDN, I see that the abstract representation of a database appears to be the DataSet class. I also see that I can use "data adapter" classes (e.g. OdbcDataAdapter) to connect a...
0
4749
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 to do that using .NET code. I prefer using code instead of wizards, because you are completely in charge of connections. This article is written for both Visual Basic.NET 2005 and C# 2005 and will discuss how to use an MS Sql database. OleDB works...
0
8384
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8896
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2798
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.