473,657 Members | 3,021 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.AcceptChange s 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
LoadFromDatabas e
SaveToXML

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

End Sub

Sub LoadFromDatabas e
ds.tables.add(" companies")
dim cn as new sqlconnection(" data source=...")
dim cmd as new sqlcommand("sel ect * from companies")
dim da as new sqldataadaptor( cmd)
da.fill(ds.tabl es("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.ta bles("companies ")
dim cn as new sqlconnection(" data source=...")
dim cmd as new sqlcommand9'sel ect * from companies")
dim da as new sqldataadaptor( cmd)
dim cb as new sqlcommandbuild er(da)
da.update(dt)
End Sub

Oct 22 '07 #1
0 1189

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

Similar topics

3
1518
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 local XML document (C:\mydoc.xml) 2.- Bind it to a Datagrid. That is all!
5
6528
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 behind a(simply bcaz it is not recognized in the code behind IDE) and it does not make a server trip. HTML server Controls should be preferred over Web Server controls as they are light weight than ASP.NET web Server controls.(If they have same...
2
2443
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. Then I want the windows client to call a aspx page passing in the sessionID as a parameter and therefore could access the dataset for further processing. So, from the web service call, how do I: 1) get the session ID 2) then from the aspx page,...
7
9006
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 can encode something using: C#: System.Security.Cryptography (to encode) and
5
1427
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 such that the clients know the latest configuration information and the server contains completed survey data from the clients. Currently I'm accomplishing this by using a few special database tables to control the flow of information, and using XML...
7
2770
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 (URL_B), get the content from the PHP server (if it exists) and then serve it out via IIS. If the content does not exist then I need to pass the request through to the IIS server and serve the pages from there. All of this needs to be done...
6
3083
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). What is the difference between SQL Server 2000 and SQL Server Express? 2). What changes (if any) do I have to make to make the website work with SQL Server express ?
1
6909
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 for a linked server to an ACCESS database. Thanks in Advance!
5
2776
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 send each of these entries individually to another server using fputs. The server will send 1 response (a lin of text) back for each item
0
8302
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,...
0
8820
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8601
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7314
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, 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...
0
5630
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
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
2
1601
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.