473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Server -> Dataset -> SQL Server

I am developing an application that will be able to be used offline from the
SQL server and am trying to come up with a good way to do this. My thought at
this moment is to basically work "offline" all the time and sync on a regular
basis when connected.

To do this, I have written several procedures to load and save data from the
database and an XML file. However, when I load the informatiom from the XML
file and then try to save it to the database, it's acting as if every record
is a new record instead of updating existing records, and since the records
have the same primary key value as records already in the database, the
program is throwing an exception, as it should. What I want it to do is to
know that the records are existing records and that they should update the
database, not add to it (unless it IS a new record, in which case I'd want it
to add - but I haven't gotten there yet)

A condensed version of my code is below (this is enough to cause the
problem). I'm testing in a console app.

Any ideas? I've had a little luck by sending ds.AcceptChanges after I load
the dataset originally from the XML. But once I do that more than once, I
lose the first set of changes that I made to the dataset. I'm thinking I may
be into something with DiffGrams, but am not sure where to get some info on
that.

-------------------
dim ds as Database

Sub Main
'Load from the database, save to an XML file
ds=new dataset
LoadFromDatabase
SaveToXML

'Reset the dataset, and then load from the XML, and update the database
ds=new dataset
LoadFromXML
SaveToDATABASE

End Sub

Sub LoadFromDatabase
ds.tables.add("companies")
dim cn as new sqlconnection("data source=...")
dim cmd as new sqlcommand("select * from companies")
dim da as new sqldataadaptor(cmd)
da.fill(ds.tables("companies")
End Sub

Sub SaveToXML
ds.WriteXML("c:\data.xml")
End Sub

Sub LoadFromXML
ds.ReadXML("c:\data.xml")
End Sub

Sub SaveToDatabase
dim dt as datatable=ds.tables("companies")
dim cn as new sqlconnection("data source=...")
dim cmd as new sqlcommand9'select * from companies")
dim da as new sqldataadaptor(cmd)
dim cb as new sqlcommandbuilder(da)
da.update(dt)
End Sub

Oct 22 '07 #1
0 1182

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

Similar topics

3
1508
by: Vico | last post by:
Hi! I have a windows forms application and , what I basically do is: 1.- Instanciate a DataSet. 2.- Instanciate a XMlDataDocument attaching the DataSet to it. 3.- Load XmlDataDocument with a...
5
6520
by: siaj | last post by:
Hello All, Can any one give me a clue when to use Web Server controls/ HTML server controls/HTML Controls. As I understand .. HTML controls should be used if u dont need to refer it in the code...
2
2435
by: moondaddy | last post by:
I want to cache a dataset on a server via a web service. I was thinking of caching it in a session object and returning the session ID as a string in the web service back to the windows client. ...
7
8994
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
5
1421
by: David Harris | last post by:
I am developing a type of data warehouse. Basically, we have 20 client survey machines that are each separated from the server by space and lack of network. Yet both need to speak to each other...
7
2759
by: Electric Co. | last post by:
Hello, note: This is for a Faculty web site that is undergoing a migration to an open source solution so my motives are legit. I need to build a relay from IIS handling URL_A to a PHP server...
6
3080
by: Grey Alien | last post by:
I have an ASP.Net website that was developed using SQL Server 2000. I want to 'port' it to use SQL Server Express, since I don't have SQL Server 2000 (besides my db is less than 1GB). Questions:...
1
6901
by: gdev | last post by:
I'm Trying to create a linked server from an SQL Server to another SQL Server on another machine. Can anyone suggest some good reference material or tutorials?? So far I'm only finding examples...
5
2771
by: matt | last post by:
This is a strange one but I've been stuck on it for days. Any help appreciated. THE PLAN: I've a database that I use a script to grab all the entries for a particular field. I then want to...
0
7198
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,...
0
7072
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...
0
7271
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
7319
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
5570
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,...
0
4666
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...
0
1498
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 ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.