473,406 Members | 2,894 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,406 software developers and data experts.

"DataSet.Merge()" simple problem

Hi there,

Can anyone explain the following (very) simple scenario.

1) I make an exact copy of my "DataSet" and delete one record from a given
table (in the copy)
2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to
"DataSet.Merge()" on the original copy
3) If I now inspect the original copy, it shows that the record has *not*
been deleted from the table. However, a call to "GetChanges()" does show my
deleted record.

Why doesn't the record get deleted from the original table after the merge
in step 2? Note that I've inspected my original "DataSet" after step 2 as
well as the "DataSet" returned by "DataSet.GetChanges()". Apparently
"DataSet.GetChanges()" returns a "DataSet" that's completely empty of data
except for the one affected table which contains the single deleted record.
That record is then simply added to the table in the original "DataSet" when
"DataSet.Merge()" is called. The original table therefore winds up with two
copies of the record, the origiinal and the deleted. Does anyone know what's
going on here. Thanks in advance.
May 19 '07 #1
5 16683
Hi,
I am not entirely sure if i had grasped your query correctly.I have written
a code snippet in C# Windows App and it is working perfectly well.

DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);

ds1.Tables[0].Rows.RemoveAt(0);

DataSet ds2 = new DataSet();

ds2 = ds1.GetChanges();

ds1.AcceptChanges();

ds1.Merge(ds2);

MessageBox.Show(ds1.Tables[0].Rows.Count.ToString());
please do let me know if this is what you are trying to do.
--
Thanks and Regards.
Manish Bafna.
MCP and MCTS.

"Mark Chambers" wrote:
Hi there,

Can anyone explain the following (very) simple scenario.

1) I make an exact copy of my "DataSet" and delete one record from a given
table (in the copy)
2) I invoke "DataSet.GetChanges()" on the above copy and pass the results to
"DataSet.Merge()" on the original copy
3) If I now inspect the original copy, it shows that the record has *not*
been deleted from the table. However, a call to "GetChanges()" does show my
deleted record.

Why doesn't the record get deleted from the original table after the merge
in step 2? Note that I've inspected my original "DataSet" after step 2 as
well as the "DataSet" returned by "DataSet.GetChanges()". Apparently
"DataSet.GetChanges()" returns a "DataSet" that's completely empty of data
except for the one affected table which contains the single deleted record.
That record is then simply added to the table in the original "DataSet" when
"DataSet.Merge()" is called. The original table therefore winds up with two
copies of the record, the origiinal and the deleted. Does anyone know what's
going on here. Thanks in advance.
May 19 '07 #2
Thanks for the feedback. Try this instead:

///////////////////////////////////////////////////
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);
ds1.AcceptChanges();

DataSet ds2 = ds1.Copy();
ds2.Tables[0].Rows[0].Delete(); // Delete ID 1

DataSet ds3 = ds2.GetChanges();
ds1.Merge(ds3);
///////////////////////////////////////////////////

After the merge, "ds1" contains the original (unaltered) rows plus one extra
(deleted) row with ID 1. Shouldn't the original row with ID 1 simply be
deleted instead?
May 19 '07 #3
Mark,

I miss the primary key in your tables?

Cor

"Mark Chambers" <no_spam@_nospam.comschreef in bericht
news:OQ****************@TK2MSFTNGP03.phx.gbl...
Thanks for the feedback. Try this instead:

///////////////////////////////////////////////////
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
dt1.Columns.Add("ID", typeof(int));

DataRow dr1 = dt1.NewRow();
dr1[0] = 1;
dt1.Rows.Add(dr1);

DataRow dr2 = dt1.NewRow();
dr2[0] = 2;
dt1.Rows.Add(dr2);

ds1.Tables.Add(dt1);
ds1.AcceptChanges();

DataSet ds2 = ds1.Copy();
ds2.Tables[0].Rows[0].Delete(); // Delete ID 1

DataSet ds3 = ds2.GetChanges();
ds1.Merge(ds3);
///////////////////////////////////////////////////

After the merge, "ds1" contains the original (unaltered) rows plus one
extra (deleted) row with ID 1. Shouldn't the original row with ID 1 simply
be deleted instead?

May 19 '07 #4
I miss the primary key in your tables?

Hmmm, very strange. When I add the primary key to this example (forget it
the first time - thanks) it works fine. In my own code however the primary
keys are there but it doesn't work. This problem is almost identical to
another one I just found here (by a C# MVP):

http://forums.microsoft.com/MSDN/Sho...32312&SiteID=1

I'll have to play around with this some more to figure out what's going on.
It seems like there's a possible MSFT bug somewhere.
May 19 '07 #5
>I miss the primary key in your tables?
>
Hmmm, very strange. When I add the primary key to this example (forget it
the first time - thanks) it works fine. In my own code however the primary
keys are there but it doesn't work. This problem is almost identical to
another one I just found here (by a C# MVP):

http://forums.microsoft.com/MSDN/Sho...32312&SiteID=1

I'll have to play around with this some more to figure out what's going
on. It seems like there's a possible MSFT bug somewhere.
Ok, thanks for each of your help. It was the primary key after all. The
designer apparently reset it in one of my tables without my knowledge. None
of these keys have been touched by me in ages however but the designer isn't
always stable and does things like this from time-to-time (as an example,
the forms designer frequently sets "Forms.CancelButton" back to null for no
apparent reason). Anyway, thanks again (appreciated).
May 19 '07 #6

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

Similar topics

6
by: Nick | last post by:
excuse me!! may i ask a simple problem here? if i dynamically allocate a memory(ex. new in C++ or malloc in C) in a sub-function and forget free the space end of the sub-function. does it...
1
by: newbie001 | last post by:
I have the following code in a listview control's initList function (called from form_load event). i can't understand why the listview box still appears blank with no columns or listview items. ...
3
by: Mark Allison | last post by:
Hi, VERY simple problem! if (regServer.UseTrustedConnection == 1) { string connectionString = "server=" + regServer.Name + "; Trusted_Connection=yes; database=master"; } else
18
by: Sender | last post by:
Yesterday there was a very long thread on this query. (You can search on this by post by 'sender' with subject 'Simple Problem' post date Oct 7 time 1:43p) And in the end the following code was...
12
by: Peter Proost | last post by:
Hi group, I've got what seems a simple problem, but I can't find the solution. I've got a textbox and a handheld scanner to scan barcodes, the scanner just generates keypresses like a keyboard...
2
by: Simon Harvey | last post by:
Hi everyone, I'm having a really simple problem - I can't seem to insert a null value into the database. When I do it tells me that the procedure expects the parameter and that I'm not providing...
4
by: R.A.M. | last post by:
Hi I have very simple problem - I need to process asp:Button click at server. I have written (my experience is little) in .aspx: <asp:Button ID="GoTo" runat="server" Text="Go To"...
8
by: rdrink | last post by:
I am just getting into pysqlite (with a fair amount of Python and MySQL experience behind me) and have coded a simple test case to try to get the hang of things... yet have run into a 'stock...
7
by: axlq | last post by:
I know this is a simple problem but it bedevils me. I'd like to have a container with two columns with the following properties: 1. Both columns dynamically adjust their width to fit their...
6
by: Gun Slinger | last post by:
Hi guys, I have a simple problem which i cant seem to figure out. Im not sure if its my fault, or just VS2008.. I have a group box, which i change its name to show a user that the contents of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
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...
0
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...

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.