//-----------------------------------------------------------------------
// This file is part of the Microsoft. NET Framework SDK code samples.
// Http://asp.dotnetheaven.com/
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This source code is intended only as a supplement to Microsoft
// Development tools and/or on-line documentation. See these other
// Materials for detailed information regarding Microsoft code samples.
//
// This code and information are provided as is without warranty of any
// Kind, either expressed or implied, including but not limited to
// Implied warranties of merchantability and/or fitness for
// Particle purpose.
//-----------------------------------------------------------------------
Using system;
Using system. collections;
Using system. componentmodel;
Using system. Data;
Using system. drawing;
Using system. Web;
Using system. Web. sessionstate;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. htmlcontrols;
Using system. Data. sqlclient;
Using system. xml;
Using system. text;
Using system. IO;
Namespace Microsoft. samples. howto. adonet
{
/// <Summary>
/// Summary description for webform1.
/// </Summary>
Public class xmlfromsqlsrv: system. Web. UI. Page
{
Stringbuilder builder = new stringbuilder ();
Protected system. Web. UI. htmlcontrols. htmlform output;
Private void page_load (Object sender, system. eventargs E)
{
Run ();
This. Output. innerhtml = builder. tostring ();
}
Public void run ()
{
String sconnection = "Server = (local) \ sqlexpress; Integrated Security = sspi; database = northwind ";
Sqlconnection mysqlconnection = new sqlconnection (sconnection );
Sqlcommand mysqlcommand = new sqlcommand ("select * from MERs for XML auto, xmldata", mysqlconnection );
Mysqlcommand. commandtimeout = 15;
Try
{
Mysqlconnection. open ();
// Now create the dataset and fill it with XML data.
Dataset mydataset1 = new dataset ();
Mydataset1.readxml (mysqlcommand. executexmlreader (), xmlreadmode. Fragment );
// Modify to match the other Dataset
Mydataset1.datasetname = "newdataset ";
// Get the same data through the provider.
Sqldataadapter mysqldataadapter = new sqldataadapter ("select * from MERs", sconnection );
Dataset mydataset2 = new dataset ();
Mysqldataadapter. Fill (mydataset2 );
// Write data to files: data1.xml and data2.xml for comparison.
Mydataset1.writexml (path. gettemppath () + "data1.xml ");
Mydataset2.writexml (path. gettemppath () + "data2.xml ");
Builder. append ("data has been writen to the output files: data1.xml and data2.xml <br/> ");
Builder. append ("<br/> ");
Builder. append ("********************* data1.xml **************** * *** <br/> ");
Builder. append (mydataset1.getxml () + "<br/> ");
Builder. append ("<br/> ");
Builder. append ("********************* data2.xml **************** * *** <br/> ");
Builder. append (mydataset2.getxml () + "<br/> ");
}
Catch (exception E)
{
Builder. append ("<br/>" + E. tostring ());
}
Finally
{
Mysqlconnection. Close ();
}
}
# Region web form designer generated code
Override protected void oninit (eventargs E)
{
//
// Codegen: This call is required by the ASP. NET web form designer.
//
Initializecomponent ();
Base. oninit (E );
}
/// <Summary>
/// Required method for designer support-do not modify
/// The contents of this method with the code editor.
/// </Summary>
Private void initializecomponent ()
{
This. Load + = new system. eventhandler (this. page_load );
}
# Endregion
}
}