Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

trying to use diffgram to update database

Hi there.

Im trying to use a diffgram xml message to update the northwind database in sql server.

the code im using executes but the changes are not updated. The code im using is from a text book. The code is supposed to change the contact name from Maria Anders to Maria in the customers table. I've added a reference to the SQLXML .NET assembly

This is the xml fiile: diffgram.xml

<?xml version="1.0" standalone="yes"?>







ALFKI

Maria









ALFKI

Maria Anders







visual studio has underlined "Customer1" and the tooltiptext states that another object on this page is already using the ID "Customer1" How ever this is how the xml is presented in the book. Im sure this is why the update is not working but im not entirely sure. any help would be much appreciated.

This is the c# code:

using Microsoft.Data.SqlXml;

using System.IO;

private void btnUpdate_Click(object sender, System.EventArgs e)

{

SqlXmlCommand sxc = new SqlXmlCommand(@"data source=(local)HOME;" +

"database=Northwind;" + "Integrated Security=SSPI");

// Set up the DiffGram

sxc.CommandType = SqlXmlCommandType.DiffGram;

sxc.SchemaPath = @"....diffgram.xsd";

FileStream fs = new FileStream(@"....diffgram.xml", FileMode.Open);

sxc.CommandStream = fs;

try

{

// And execute it

sxc.ExecuteNonQuery();

label1.Text = "Database was updated";

}

catch (SqlXmlException ex)

{

ex.ErrorStream.Position = 0;

string strErr = (new StreamReader(ex.ErrorStream).ReadToEnd());

label2.Text = strErr;

}

catch (Exception ex)

{

label3.Text = ex.Message;

}

finally

{

fs.Close();

}

}

and this is the schema:





















Sign In or Register to comment.