473,545 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataAdapter.Upd ate() and DataTable.GetCh anges() side effect.

Got a question about the side effect of DataAdapter.Upd ate() and
DataTable.GetCh anges().

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 JobListDataTabl eFromAccessComm itChange()
{
System.Data.Dat aTable oChangeDataTabl e;

try
{
if (this.jobListDa taTable.HasErro rs)
{
throw (new
System.Applicat ionException(Er rDatabaseUpdate ));
}

oChangeDataTabl e = this.jobListDat aTable.GetChang es();
if (oChangeDataTab le != null)
{
this.JobListDat aAdapter.Update (oChangeDataTab le);

foreach (System.Data.Da taRow oDataRow in
oChangeDataTabl e.Rows)
{
if (oDataRow[JobDataGridView ColumnId] ==
System.DBNull.V alue)
{
this.jobListDat aTable.Clear();

this.jobListDat aAdapter.Fill(t his.jobListData Table);
break;
}
}

if (this.jobListDa taTable.HasErro rs)
{
throw (new
System.Applicat ionException(Er rDatabaseUpdate ));
}
}
}
catch (Exception ex)
{
throw (ex);
}

return;
}
Before "this.JobListDa taAdapter.Updat e(oChangeDataTa ble);" oChangeDataTabl e
contains 1 row. After the Update(), oChangeDataTabl e contains 0 row.

Does anyone knows why? The followings are some of my guesses

1. DataTable.GetCh anges() contains a collection that points to the same
DataRow as the DataTable. Hence, when Update() causes the deleted row to be
removed, oChangeDataTabl e's collection loses the removed row.

2. The part I do not understand is if oChangeDataTabl e'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 oChangeDataTabl e'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.GetCh anges() simply returns a reference to this managed table?

Sorry for the bubbling here. I am typing while thinking.
--
George
Jun 16 '06 #1
4 11152
I will answer my own question post here....

The side effect is caused by the AcceptChangesDu ringUpdate flag in
DataAdapter. I have been passing the table obtained from
DataTable.GetCh anges() into DataAdapter.Upd ate().

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.Upd ate() and
DataTable.GetCh anges().

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 JobListDataTabl eFromAccessComm itChange()
{
System.Data.Dat aTable oChangeDataTabl e;

try
{
if (this.jobListDa taTable.HasErro rs)
{
throw (new
System.Applicat ionException(Er rDatabaseUpdate ));
}

oChangeDataTabl e = this.jobListDat aTable.GetChang es();
if (oChangeDataTab le != null)
{
this.JobListDat aAdapter.Update (oChangeDataTab le);

foreach (System.Data.Da taRow oDataRow in
oChangeDataTabl e.Rows)
{
if (oDataRow[JobDataGridView ColumnId] ==
System.DBNull.V alue)
{
this.jobListDat aTable.Clear();

this.jobListDat aAdapter.Fill(t his.jobListData Table);
break;
}
}

if (this.jobListDa taTable.HasErro rs)
{
throw (new
System.Applicat ionException(Er rDatabaseUpdate ));
}
}
}
catch (Exception ex)
{
throw (ex);
}

return;
}
Before "this.JobListDa taAdapter.Updat e(oChangeDataTa ble);" oChangeDataTabl e
contains 1 row. After the Update(), oChangeDataTabl e contains 0 row.

Does anyone knows why? The followings are some of my guesses

1. DataTable.GetCh anges() contains a collection that points to the same
DataRow as the DataTable. Hence, when Update() causes the deleted row to be
removed, oChangeDataTabl e's collection loses the removed row.

2. The part I do not understand is if oChangeDataTabl e'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 oChangeDataTabl e'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.GetCh anges() simply returns a reference to this managed table?

Sorry for the bubbling here. I am typing while thinking.
--
George

Jun 16 '06 #2
Hi George,

You can call Update on jobListDataTabl e 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.)

Jun 19 '06 #3
Kevin,

Do you mean DataTable.Updat e()? I am not able to locate this public method.
Please let me know if I misundertand your previous post.

Note: Currently, I use OleDbDataAdapte r.Update(<DataT able>). It does work
as I expect.

Thanks,
--
George
"Kevin Yu [MSFT]" wrote:
Hi George,

You can call Update on jobListDataTabl e 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.)

Jun 19 '06 #4
No, I mean call OleDbDataAdapte r.Update(jobLis tDataTable), 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.)

Jun 20 '06 #5

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

Similar topics

5
2237
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 DataTable first and I then want to roll through the DataTable while in memory checking for errors and then commit the rows to my database table (btw this...
13
2070
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 OleDbCommand with an SQL String and the connection it has a DataAdapter with the command then it fills the DataSet's DataTable with the streamed data.
4
1778
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 you. ====================================== Private Sub SaveChanges(ByVal aContainer As Object)
8
2678
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. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call...
3
8911
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 but I need to write a utility that can transfer a row of data from the Production to the Development servers. I wrote the code below, which doesn't...
6
13981
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 = conn da.UpdateCommand.CommandText = "Update tbl1 set fld1 = 'test' where ID = 1" da.Update(tblx) '--tblx/tbl1 not getting updated here.
5
5029
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 encountered that? Am I not setting this field properly? The following are some of the snippets of the codes which may help explain
2
4556
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
1
1647
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 a stored procedure and getchanges will know, or do I need to do this update using a DataAdapter. Currently, I'm not getting any rows with GetChanges,...
0
7478
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7668
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. ...
0
7923
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...
1
7437
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7773
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...
0
4960
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...
0
3466
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...
1
1901
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
1
1025
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.