Databases Reference
In-Depth Information
n
Note
If you're unfamiliar with XML, don't worry. ADO.NET doesn't require any detailed knowledge of it.
Of course, the more you know, the better you can understand what's happening transparently.
Try It Out: Extracting a Dataset to an XML File
You can preserve the contents and schema of a dataset in one XML file using the dataset's
WriteXml
method or in separate files using
WriteXml()
and
WriteXmlSchema()
.
WriteXml()
is
overloaded, and in this example we'll show a version that extracts both data and schema.
1.
Add a new C# Console Application project named WriteXML to your Chapter13
solution. Rename
Program.cs
to
WriteXML.cs
.
2.
Replace the code in
WriteXML.cs
with the code in Listing 13-9.
Listing 13-9.
WriteXML.cs
using System;
using System.Data;
using System.Data.SqlClient;
namespace Chapter13
{
class WriteXML
{
static void Main(string[] args)
{
// connection string
string connString = @"
server = .\sqlexpress;
integrated security = true;
database = northwind
";
// query
string qry = @"
select
productname,
unitprice
from
products
";
Search WWH ::
Custom Search