It seems like this should be easy, but it has proven to be quite
painful.
I have an existing dataset, which I used the GetChanges and WriteXML
functions upon to write out a DiffGram to a local XML file. I want to
use this same dataset (in another instance of the application) and the
DiffGram to display the changes in the DataGridView as they existed
after the user made his/her change.
In English:
A user will open the application, which displays data in a grid, make
their changes and hit save. This will save only the changes (in a
diffgram) to a local file. They will then come in the next day and
make a few more changes. I would like the application to grab the
original data and merge their previous changes into the original data
and display that on the grid.
I've used both ReadXML as well as Merge, but ReadXML only appends the
rows in the DiffGram to the end, and Merge doesn't seem to do anything
but toss the DiffGram square into the garbage.
Here is my code:
Dim dsList As New DataSet
Dim dsChanges As New DataSet
mySqlDataAdapte r.AcceptChanges DuringFill = False
mySqlDataAdapte r.Fill(dsList)
If File.Exists(str Changes) AndAlso
File.ReadAllTex t(strChanges).L ength 0 Then
' ReadXml on the original dataset just adds it to the
end
'dsList.ReadXml (strChanges, XmlReadMode.Dif fGram)
'.Tables(0).
dsChanges.ReadX ml(strChanges, XmlReadMode.Dif fGram)
dsList.Merge(ds Changes, True)
End If
grdResults.Data Source = dsList.Tables(0 )
Please help! 1 5021
The solution is as painful as I had hoped...
Turns out that you need some form of unique ID (primary key) to match
the data, so I had to create a new column in the original dataset as an
identity field. You then need to set the primary key in both datasets
so that it knows how to match them. In addition, instead of merging
the changes back onto the original list, you must merge the list onto
the changes dataset. In order to do that, you need to grab the schema
of the original data set and set it to the changes schema. Confused?
Hopefully the code will be clearer than the description:
Dim mySqlDataAdapte r As SqlDataAdapter = New
SqlDataAdapter( cmdList)
Dim dsList As New DataSet
Dim dsChanges As New DataSet
' Populate the list from the DB
mySqlDataAdapte r.Fill(dsList)
' If the changes file exists (in diffgram format)
If File.Exists(str Changes) AndAlso
File.ReadAllTex t(strChanges).L ength 0 Then
' Write out the schema from the list
File.WriteAllTe xt("D:\temp\Sch ema.xml",
dsList.GetXmlSc hema(), System.Text.Enc oding.Unicode)
' Set the schema of the changes dataset
dsChanges.ReadX mlSchema("D:\te mp\Schema.xml")
' Populate the changes dataset
dsChanges.ReadX ml(strChanges, XmlReadMode.Dif fGram)
' Set the primary key values for both datasets
dsList.Tables(0 ).PrimaryKey = New DataColumn()
{dsList.Tables( 0).Columns("ID" )}
dsChanges.Table s(0).PrimaryKey = New DataColumn()
{dsChanges.Tabl es(0).Columns(" ID")}
' Merge the list onto the changes, not the other way
around
dsChanges.Merge (dsList, True)
' Set the datasource of the grid
grdResults.Data Source = dsChanges.Table s(0)
Else
' Set the datasource of the grid
grdResults.Data Source = dsList.Tables(0 )
End If This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: IMS.Rushikesh |
last post by:
Hi All,
I want to serialize an object which contain the DataTable. As DataSet
is MarshalByRef object and is serializable. I am using it directly.
Even my data is also serialize and save it to XML file.
Now as DataSet serialize, it's creating some extra information (schema
information), And i don't need that. I only want to store the data in
XML format. I don't want to store extra details like namespace etc...
As it's increase XML file...
|
by: Patrik |
last post by:
Hi
I want to return a dataset from a webservice and exclude the schema.
How can I do this?
/Patrik
|
by: Mav |
last post by:
Hello,
I'm trying to fill a dataset with the data of a diffgram xml-file.
I expect a dataset with datasetname "ComputerSystem" filled with 1
table (tables.count = 1). The only thing i've got is an empty dataset
(datasetname = "NewDataSet", tables.count=0). You find a code snippet
in attach. Any ideas?
Thanks,
|
by: John Lee |
last post by:
Hi,
When I use DataSet.WriteXml(filename, XmlWriteMode.DiffGram), the xml file
contains current values (at <InvDataSet> node) and original value (at
<diffgr:before> node) - this means the original values are stored somewhere
in DataSet, Can someone tell me how can I access those original values from
code?
Thanks very much!
|
by: JJ |
last post by:
Hi,
I have a DataSet that has no records in it from Database. I use this for
just collecting records that I have been working on. I have a new worker
dataset that goes out to database and gets a single record from database for
updates to existing record is necessay. Now I want to take the dataset that
has been updated and update the collection Dataset. Once everything is done I
send the whole thing at one time to database to do...
| |
by: Brian Keating |
last post by:
wonder if anyone can help me here,
i've a framework 1.1 dataset which i serialize in framework 1.1 and
deserialize in framework 2.0.
This is fine, problem is that i want to modify some of the records in
framework 2.0 and serialize the data so framework 1.1 can deserialize it and
do what it required.
Is this possible?
|
by: KillerJ |
last post by:
I found a post about this exact issue:
http://groups.google.com/group/microsoft.public.dotnet.xml/browse_thread/thread/1dfeb38170cb0b1/ea073666a4035bd5?lnk=st&q=decimal+parse+error+loading+dataset&rnum=6&hl=en#ea073666a4035bd5
but it only shows how to correct the issue manually, not whether it is
a known bug.
My situation is slightly different only in that the xml data and schema
I have are coming directly from the DataSet using:...
|
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.
|
by: processoriented |
last post by:
I am trying to find the best approach to do something here...
situation is this... One of the tables in my dataset is a "Work Order"
table with information about what needs to be done and where. Say my
user goes on site to do the work associated with the work order, and
while he is there, he discovers that the customer's phone number has
changed. Should be no problem, he opens up the app, looks at his list
of open work orders, finds the...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |