Got a question about the side effect of DataAdapter.Update() and
DataTable.GetChanges().
Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove)
a row in the data table and call the following method.
public void JobListDataTableFromAccessCommitChange()
{
System.Data.DataTable oChangeDataTable;
try
{
if (this.jobListDataTable.HasErrors)
{
throw (new
System.ApplicationException(ErrDatabaseUpdate));
}
oChangeDataTable = this.jobListDataTable.GetChanges();
if (oChangeDataTable != null)
{
this.JobListDataAdapter.Update(oChangeDataTable);
foreach (System.Data.DataRow oDataRow in
oChangeDataTable.Rows)
{
if (oDataRow[JobDataGridViewColumnId] ==
System.DBNull.Value)
{
this.jobListDataTable.Clear();
this.jobListDataAdapter.Fill(this.jobListDataTable );
break;
}
}
if (this.jobListDataTable.HasErrors)
{
throw (new
System.ApplicationException(ErrDatabaseUpdate));
}
}
}
catch (Exception ex)
{
throw (ex);
}
return;
}
Before "this.JobListDataAdapter.Update(oChangeDataTable); " oChangeDataTable
contains 1 row. After the Update(), oChangeDataTable contains 0 row.
Does anyone knows why? The followings are some of my guesses
1. DataTable.GetChanges() contains a collection that points to the same
DataRow as the DataTable. Hence, when Update() causes the deleted row to be
removed, oChangeDataTable's collection loses the removed row.
2. The part I do not understand is if oChangeDataTable's collection still
points to the deleted DataRow, shouldn't it still be in memory and not
garbage collected?
3. Does DataRow.Dispose() has anything to do with this?
4. How is oChangeDataTable's collection is smart enough to update its count
from 1 to 0?
5. Unless the original DataTable actually maintains the change data table
and DataTable.GetChanges() simply returns a reference to this managed table?
Sorry for the bubbling here. I am typing while thinking.
--
George 4 11140
I will answer my own question post here....
The side effect is caused by the AcceptChangesDuringUpdate flag in
DataAdapter. I have been passing the table obtained from
DataTable.GetChanges() into DataAdapter.Update().
This does exactly what the specification stated, but not what I wanted.
Thanks,
--
George
"George" wrote: Got a question about the side effect of DataAdapter.Update() and DataTable.GetChanges().
Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove) a row in the data table and call the following method.
public void JobListDataTableFromAccessCommitChange() { System.Data.DataTable oChangeDataTable;
try { if (this.jobListDataTable.HasErrors) { throw (new System.ApplicationException(ErrDatabaseUpdate)); }
oChangeDataTable = this.jobListDataTable.GetChanges(); if (oChangeDataTable != null) { this.JobListDataAdapter.Update(oChangeDataTable);
foreach (System.Data.DataRow oDataRow in oChangeDataTable.Rows) { if (oDataRow[JobDataGridViewColumnId] == System.DBNull.Value) { this.jobListDataTable.Clear();
this.jobListDataAdapter.Fill(this.jobListDataTable ); break; } }
if (this.jobListDataTable.HasErrors) { throw (new System.ApplicationException(ErrDatabaseUpdate)); } } } catch (Exception ex) { throw (ex); }
return; }
Before "this.JobListDataAdapter.Update(oChangeDataTable); " oChangeDataTable contains 1 row. After the Update(), oChangeDataTable contains 0 row.
Does anyone knows why? The followings are some of my guesses
1. DataTable.GetChanges() contains a collection that points to the same DataRow as the DataTable. Hence, when Update() causes the deleted row to be removed, oChangeDataTable's collection loses the removed row.
2. The part I do not understand is if oChangeDataTable's collection still points to the deleted DataRow, shouldn't it still be in memory and not garbage collected?
3. Does DataRow.Dispose() has anything to do with this?
4. How is oChangeDataTable's collection is smart enough to update its count from 1 to 0?
5. Unless the original DataTable actually maintains the change data table and DataTable.GetChanges() simply returns a reference to this managed table?
Sorry for the bubbling here. I am typing while thinking.
-- George
Hi George,
You can call Update on jobListDataTable directly to update the database.
This will make things much easier. :-)
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Kevin,
Do you mean DataTable.Update()? I am not able to locate this public method.
Please let me know if I misundertand your previous post.
Note: Currently, I use OleDbDataAdapter.Update(<DataTable>). It does work
as I expect.
Thanks,
--
George
"Kevin Yu [MSFT]" wrote: Hi George,
You can call Update on jobListDataTable directly to update the database. This will make things much easier. :-)
Kevin Yu Microsoft Online Community Support
================================================== ========================== ========================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== ========================== ==========================
(This posting is provided "AS IS", with no warranties, and confers no rights.)
No, I mean call OleDbDataAdapter.Update(jobListDataTable), which means
you're right currently.
Kevin Yu
Microsoft Online Community Support
================================================== ==========================
==========================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ==========================
==========================
(This posting is provided "AS IS", with no warranties, and confers no
rights.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: randy |
last post by:
Hello all,
I have a DataTable which I am building column by column and adding rows
after each new column. The DataTable columns match the columns in my
database table. I'm building the...
|
by: Doug Bell |
last post by:
Hi,
I thought I had this sorted this morning but it is still a problem.
My application has a DataAccess Class.
When it starts, it:
Connects to a DB (OLE DB)
If it connects it uses an...
|
by: astro |
last post by:
I would like to build some generic code that is able to figure out the
correct dataAdapter to apply changes to given a form with several
dataAdapters.
Any suggestions on the following?
Thank...
|
by: Zorpiedoman |
last post by:
I keep getting a concurrency exception the second time I make a change and
attempt to update a dataadapter. It appears this is by design, so there must
be something I can do to avoid it.
...
|
by: RSH |
last post by:
Hi,
I have a situation in where i have two instances of SQL server, the first is
our Production Environment, the second is our Development environment. Both
servers contain the same databases...
|
by: Rich |
last post by:
Dim da As New SqlDataAdapter("Select * from tbl1", conn)
dim tblx As New DataTable
da.Fill(tblx) '--works OK up to this point
da.UpdateCommand = New SqlCommand
da.UpdateCommand.Connection =...
|
by: George |
last post by:
I have set DataAdapter.AcceptChangesDuringUpdate = true;
However, I find that I still need to call AcceptChanges on the associated
DataTable,
DataTable.AcceptChanges();
Has anyone...
|
by: Rich |
last post by:
Hello,
Is there a way to capture the Records Affected count when performing a table
Update on a Sql Server table using a DataAdapter? How is this done?
Thanks,
Rich
|
by: daranee |
last post by:
Documentation on GetChanges say the following: Gets a copy of the DataSet that contains all changes made to it since it was loaded or AcceptChanges was last called.
Does this mean I can update via...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |