SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Can it possible to perform multiple Update with XML format query


Can it possible to perform multiple Update with XML format query

Author
Message
Nitesh katare
Nitesh katare
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 4
I got an Idea how to Send multiple rows to the Database from an Application
and from the below code we can even insert it to the table as u showed in the Article

like,
consider a table Emp
INSERT INTO Emp (Name, Salary)

SELECT Name, Salary FROM OPENXML (@idoc, '/ROWS/ROW', 1)
WITH (Name varchar(50), Salary int)
WHERE Salary >= 1500
ORDER BY Name

My Doubt is about how to Update multiple rows in Emp table using the below xml query

<ROWS>
<ROW>
<ID>1</ID>
<Name>Tom</Name>
<Salary>21000</Salary>
</ROW>
<ROW>
<ID>2</ID>
<Name>Nitesh</Name>
<Salary>18000</Salary>
</ROW>
<ROW>
<ID>3</ID>
<Name>Mat</Name>
<Salary>15000</Salary>
</ROW>
</ROWS>

Please help me out for updating the table with above xml Query

Thank and Regards
Nitesh katare
crackbridge
crackbridge
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 Visits: 48
Actually this is an interesting topic, but I would advice using SqlBulkCopy instead, which provide amazing performance, with just a few lines of code:

public virtual bool SqlBulkCopy(DataSet ds, string TableName) // provide ability to update any Table in the DS, assume TableName is idem for SQL and App Level
bool result = true;
using (SqlBulkCopy BulkCopy = new SqlBulkCopy(MyConnectionString))
{
BulkCopy.DestinationTableName = TableName;
try
{
BulkCopy.WriteToServer(ds.Tables[TableName]); // Write from the source to the destination.
}
catch (Exception e)
{
// Provide feedback of error issues, to be recovered using something like "DataSetErrorsShower.Show()"
ds.Tables[TableName].Rows[0].RowError = ExceptionHandler.WrapSqlException(e);
result = false;
}
if (result == true)
ds.Tables[TableName].AcceptChanges();
return result
}

Hope it helps, keep on comments.
Kind Regards,
Louis.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search