473,385 Members | 1,861 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,385 software developers and data experts.

Update the values in a SQL Server Databse coulmn of type XML.

45
Hi all,

I am developing a web application where I save a XML file into a SQL Server 2000 database. I do not face any problems in storing to xml file to the database. However, when a updated version of the same xml file is to be stored into the database I cannot do so.

Basically what I am trying to do is check the database for a perticular record. Then if the record is not present I use the INSERT statement to create the new record. But in case a record is present and needs to be updated I cannot use the UPDATE command.

Expand|Select|Wrap|Line Numbers
  1. XmlReader xr = XmlReader.Create(Server.MapPath(@"~\XmlFiles\abc.xml"));
  2. SqlConnection connection = new SqlConnection();
  3. connection = "//Some connection string//"
  4. SqlCommand cmd = new SqlCommand();
  5. cmd.Connection = connection;
  6. cmd.CommandText = "INSERT INTO tblXML(ID, Name, xmlFile) VALUES(@ID, @Name, @x)";
  7. cmd.Parameters.Add("@ID", SqlDbType.UniqueIdentifier);
  8. cmd.Parameters.Add("@Name", SqlDbType.VarChar);
  9. cmd.Parameters.Add("@x", SqlDbType.Xml);
  10. cmd.Parameters[0].Value = Guid.NewGuid();
  11. cmd.Parameters[1].Value = txtFormName.Text;
  12. cmd.Parameters[2].Value = new SqlXml(xr);
  13. int i = cmd.ExecuteNonQuery();
  14.  
this works fine. but the below code does not.
Expand|Select|Wrap|Line Numbers
  1. cmd.CommandText = "UPDATE tblXML SET xmlFile=@x WHERE //some condition//
  2. cmd.Parameters.Add("@x", SqlDbType.Xml);
  3. cmd.Parameters[0].Value = new SqlXml(xr);
  4. i = cmd.ExecuteNonQuery();

I am using C#.

can any body suggest something?

Many Thanks.
Nov 16 '07 #1
1 1319
kunal pawar
297 100+
try this one

Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters.Add("@x", SqlDbType.Xml);
  2. cmd.Parameters.Value = new SqlXml(xr);
  3. i = cmd.ExecuteNonQuery();
its work
Nov 16 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: laurie | last post by:
Hi all, I'm trying to help out a friend who has inherited a client with a PHP shopping cart application. Neither of us know PHP, but I've been muddling my way through, trying to get these old...
0
by: Chris Hall | last post by:
The records in my database are displayed in a form as follows: %> <form action="report-ammend1.42.asp" method="post"name="form"> <table border=1> <% x = 1
7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
3
by: Kevin Pedersen | last post by:
Hello, I am using an editable datagrid. After I save the changes the datagrid shows the old values. I've read the posts about the Page_Load and not binding the datagrid each time. The SQL that...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
3
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following...
4
by: tim.cavins | last post by:
I have a GridView populated by an ObjectDataSource. I am having issues passing the parameters to the objectdatasource. I have verified that the method is being called but none of the parameters...
2
by: kendrick82 | last post by:
Hi, I am developing a web application and facing a difficulty in inserting the new data in a Datatable into the MS Access databse. The below method is able to execute without any error message but...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.