How to: Use Visual C # .NET to presen a DataTable column as an XML property rather than an element (from MSDN)

xiaoxiao2021-03-06  75

The release number of this article has been CHS311937

For Microsoft Visual Basic .NET versions of this article, see

310345.

This task content

Summary requires steps to create a Visual C # .NET example

Summary How to demonstrate this article

DataTable columns are presented as Scalable Markup Language (XML) properties.

DataTable indicates a table of the relational data in the memory. You can create one

Data tables and use it alone, other Microsoft .NET frameworks can also use it, and the most common is to use it as

A member of the data set object.

Back to top

The following table summarizes the recommended hardware, software, network architecture, and service pack required:

Microsoft Windows XP, Windows 2000 or Windows NT 4.0 Service Pack 6a Microsoft Visual Studio .NET This article assumes that you are familiar with the following topics:

Visual C # .NET Syntax Scalable Markup Language (XML) ADO.NET Foundation and Syntax

Back to top

Steps to create a Visual C # .NET example

Newly built a Visual C # console application project. Add the following code to the top of the Code window: use system;

Using system.data;

Using system.data.sqlclient; Add the following code to static void main (String [] args section: SQLConnection cnpubs = new SqlConnection ("Data Source = ; user ID = ;

Password = ; Initial Catalog = Pubs; ");

SqlDataAdapter Daauthors = New SqldataAdapter ("Select * from authors", cnpubs);

DataSet DS = New Dataset ();

CNPUBS.OPEN ();

Daauthors.Fill (DS, "Authors");

DataTable DT;

DT = DS.TABLES ["Authors"];

Foreach (Datacolumn DC in DT.columns)

{

Dc.columnmapping = mappingtype.attribute;

}

DS.WriteXml (@ "c: /authors.xml);

Console.writeline ("Completed Writing XML File, Using A Dataset");

Console.read (); modify the SQLConnection string accordingly according to your environment. Press F5 to generate and run this application. "Completed Writing XML File" message will appear in the Console window. Note that the authors.xml file has been created in the specified location. Open Authors.xml. You will notice that all columns are created as attributes of each row.

Back to top

The information in this article applies to:

Microsoft ADO .NET (included in .NET Framework) Microsoft Visual C # .net (2002)

Recent Updated: 2002-2-24 (1.0) Keyword Kbadonet Kbhowto KbhowTomaster KB311937

转载请注明原文地址:https://www.9cbs.com/read-109022.html

New Post(0)