Stephane,
SQL Server is expecting the first line to look like the following:
<?xml version = "1.0" ?>
You could strip out the information in the XML string before assigning it to the CommandText.
>Thanks Cathi !
>
>but it only works if i remove the first line:
>
>
>if i leave it i get an exception :
>XML Parse Error: Unable to switch the encoding.
>
>Any idea ?
>
>
>>Hi Stephane,
>>
>>You are actually trying to update an updategram instead of a diffgram. To update this, you need to install the the SqlXml 3.0 package and use the SqlXMLCommand object.
>>
>>Here is some sample code on how to use this in ADO.NET:
>>
>>
>>SqlXmlCommand objSXC = new SqlXmlCommand("Driver={SQL
>>Server};Server=MyServer;Database=MyDatabase;Uid=MyUser; Pwd=MyPassword;");
>>
>>objSXC.CommandType = SqlXmlCommandType.UpdateGram;
>>
>>objSXC.CommandText = MyXMLstring;
>>
>>objSXC.ExecuteNonQuery ();
>>
>>
>>Here is the link to download SqlXml 3.0:
>>
>>
http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/824/msdncompositedoc.xml>>
>>>How do i save a Diffgram back to SQL Server using ADO.NET and C#? Here is the diffgram i want to save:
>>>
>>>
>>>
>>><?xml version = "1.0" encoding="Windows-1252" standalone="yes"?>
>>><root xmlns:updg="urn:schemas-microsoft-com:xml-updategram">
>>> <updg:sync>
>>> <updg:before>
>>> <testtable>
>>> <descr>BEFORE CHANGE</descr>
>>> <identity_column>5</identity_column>
>>> </testtable>
>>> </updg:before>
>>> <updg:after>
>>> <testtable>
>>> <descr>AFTER CHANGE</descr>
>>> <identity_column>5</identity_column>
>>> </testtable>
>>> </updg:after>
>>> </updg:sync>
>>></root>
>>>
>>>
-----------------------------------------
Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.comwww.prenia.comWeblog: blogs.prenia.com/cathi