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

Updating Sql Server from xml document

Okay, I have created a Customers class. This class allows a user to select
and update the customers table on an Sql Server database. I can retrieve
the datatable generated by the class. Make changes to the table. Pass the
table back to the class and update the backend with no problem However,
here is my problem: After writing the table to xml using
ds.writexml("path") and editing the document i then read the data into a
dataset and then try to update the back-end using the edited xml document.
The process errors and says i need and Insert command. Well - I should need
an insert. It is an update! What is going on?
Jul 21 '05 #1
6 1403
That is "I should not need an Insert Command" because it is an update. For
some reason the the DataViewRowState = DataViewRowState.Added. Can I
change this?
"foobar" <es***@inbizservices.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Okay, I have created a Customers class. This class allows a user to
select and update the customers table on an Sql Server database. I can
retrieve the datatable generated by the class. Make changes to the table.
Pass the table back to the class and update the backend with no problem
However, here is my problem: After writing the table to xml using
ds.writexml("path") and editing the document i then read the data into a
dataset and then try to update the back-end using the edited xml document.
The process errors and says i need and Insert command. Well - I should
need an insert. It is an update! What is going on?

Jul 21 '05 #2
> ...try to update the back-end using the edited xml document. The process errors and says i need and Insert command...

After you read the rows into the dataset, you must call AcceptChanges() since they are new, "inserted" rows.
However, calling AcceptChanges() will apply all changes to the DataSet, including previous updates.

So, perform any updates that you have first.
Then, read the xml into the DataSet.

You must specify an InsertCommand, to your DataAdapter, that can perform the inserts correctly.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"foobar" <es***@inbizservices.com> wrote in message news:eq**************@TK2MSFTNGP09.phx.gbl...
Okay, I have created a Customers class. This class allows a user to select and update the customers table on an Sql Server
database. I can retrieve the datatable generated by the class. Make changes to the table. Pass the table back to the class and
update the backend with no problem However, here is my problem: After writing the table to xml using ds.writexml("path") and
editing the document i then read the data into a dataset and then try to update the back-end using the edited xml document. The
process errors and says i need and Insert command. Well - I should need an insert. It is an update! What is going on?

Jul 21 '05 #3
Thanks Dave for your reply. Applying AcceptChanges() to the dataset before
I apply the update method doesn't do what I want it to do.
Okay here is the DataViewRowState when ds.AcceptChanges() is commented out:
//# of records added: 1
//# of CurrentRows: 1
//# of records Deleted: 0
//# of records ModifiedCurrent: 0
//# of records ModifiedOriginal: 0
//# of records .None: 0
//# of records OriginalRows: 0
//# of records Unchanged: 0
and a new record is inserted into the backend.

Here is the DataViewRowState using ds.AcceptChanges():
//# of records added: 0
//# of CurrentRows: 1
//# of records Deleted: 0
//# of records ModifiedCurrent: 0
//# of records ModifiedOriginal: 0
//# of records .None: 0
//# of records OriginalRows: 1
//# of records Unchanged: 1
and there is no change to the backend. I expected an update on the record.
"Dave" <NO*********@dotcomdatasolutions.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
...try to update the back-end using the edited xml document. The process
errors and says i need and Insert command...


After you read the rows into the dataset, you must call AcceptChanges()
since they are new, "inserted" rows.
However, calling AcceptChanges() will apply all changes to the DataSet,
including previous updates.

So, perform any updates that you have first.
Then, read the xml into the DataSet.

You must specify an InsertCommand, to your DataAdapter, that can perform
the inserts correctly.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"foobar" <es***@inbizservices.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Okay, I have created a Customers class. This class allows a user to
select and update the customers table on an Sql Server database. I can
retrieve the datatable generated by the class. Make changes to the
table. Pass the table back to the class and update the backend with no
problem However, here is my problem: After writing the table to xml
using ds.writexml("path") and editing the document i then read the data
into a dataset and then try to update the back-end using the edited xml
document. The process errors and says i need and Insert command. Well -
I should need an insert. It is an update! What is going on?


Jul 21 '05 #4
Okay, I got it working. Here is what I did:

I loaded the xml document into a DataSet (ds). Then I loaded the table
schema from the backend with the current table from the backend into a
DataTable. This is to get all primarykey information created on my
datatable and corresponding data. Finally I merged the tables using
ds.Merge and passing preserveChanges as true.

After applying these changes my DataViewRowState was:

//# of records added: 0

//# of CurrentRows: 1

//# of records Deleted: 0

//# of records ModifiedCurrent: 1

//# of records ModifiedOriginal: 1

//# of records .None: 0

//# of records OriginalRows: 1

//# of records Unchanged: 0
"foobar" <es***@inbizservices.com> wrote in message
news:eq**************@TK2MSFTNGP09.phx.gbl...
Okay, I have created a Customers class. This class allows a user to
select and update the customers table on an Sql Server database. I can
retrieve the datatable generated by the class. Make changes to the table.
Pass the table back to the class and update the backend with no problem
However, here is my problem: After writing the table to xml using
ds.writexml("path") and editing the document i then read the data into a
dataset and then try to update the back-end using the edited xml document.
The process errors and says i need and Insert command. Well - I should
need an insert. It is an update! What is going on?

Jul 21 '05 #5
Foobar,

Don't call your xml dataset a xml document. I thought that you was talking
about a file that you had exported from word or something. Reading the text
I saw now as well that it was an XML dataset.

You had luck that Dave readed it, however it is a lot better if you give the
right information with a problem direct.

Cor
Jul 21 '05 #6
I am talking about an xml document. I write a file using the
DataSet.WriteXml method. I then edit the file by opening it up in notepad.
I read the file back into a DataSet using the DataSet.ReadXml method....
Sorry that I confused you.
"Cor Ligthert" <no************@planet.nl> wrote in message
news:et**************@TK2MSFTNGP14.phx.gbl...
Foobar,

Don't call your xml dataset a xml document. I thought that you was talking
about a file that you had exported from word or something. Reading the
text I saw now as well that it was an XML dataset.

You had luck that Dave readed it, however it is a lot better if you give
the right information with a problem direct.

Cor

Jul 21 '05 #7

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

Similar topics

9
by: refer_to_website | last post by:
My VB.NET web application has a textbox where the user is allowed to enter up to 50 characters. I have a label on the form next to the textbox that tells the user how many remaining characters he...
10
by: sqlboy2000 | last post by:
Hello all, I have something very simple going on here and I'm scratching my head as to what the problem is. There are 4 items in my project, 2 webforms, a user control, and a module: ...
14
by: el_sid | last post by:
Our developers have experienced a problem with updating Web References in Visual Studio.NET 2003. Normally, when a web service class (.asmx) is created, updating the Web Reference will...
2
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm...
2
by: Rob Long | last post by:
Hi I have an HTML select element in my page and it's multiple property is disabled (one item at a time mode) but I still want to transfer all the items in the select to the server when the form...
15
by: slinky | last post by:
Thanks in advance fo rany help... I have an XML data file (well- formed) that I need to place into my website's app_data folder. I would like to have an .aspx form on my site that simply has two...
5
by: rosaryshop | last post by:
I'm working a jewelry/rosary design web site at http://www.rosaryshop.com/rosariesAndKits2.php. As the user makes selections, it updates images of various parts, giving them a preview of the...
2
by: =?Utf-8?B?TUNN?= | last post by:
I have an asp.net page that contains an update panel. Within the update panel, controls get added dynamically. During partial page post backs the controls within the panel will change. I have a...
0
by: sujata321 | last post by:
Hi, I need to update an XML file using ASP and javascript/vbscript. But this is not working.It is showing the error – ‘document’ is not defined –in the line ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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
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...

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.