Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the ADO.NET XML architecture

Shulou Source: shulou.com Published: 2022-06-02 08:17:57 10月16日 Update

This article mainly explains "how to use the ADO.NET XML architecture". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use the ADO.NET XML architecture".

Given an ADO.NET XML schema that conforms to the ADO.NET XML Schema definition language (XSD) standard, you can generate strongly typed DataSet using the XSD.exe tools provided with the Windows Software Development Kit (SDK). The following code shows the syntax for generating DataSet using this tool.

Xsd.exe / d / l:CS XSDSchemaFileName.xsd / eld / n:XSDSchema.Namespace

In this syntax, the / d instruction instructs the tool to generate DataSet,/l: tell the tool which language to use (such as C # or Visual Basic .NET). The optional / eld directive specifies that you can use LINQ to DataSet to query the generated DataSet. You can use this option when the / d option is also specified. For more information, see querying typed datasets. The optional / n: directive instructs the tool to also generate a namespace for the DataSet named XSDSchema.Namespace. The output of the command is XSDSchemaFileName.cs, which can be compiled and used in ADO.NET applications. The generated code can be compiled into libraries or modules.

The following code shows the syntax for accessing the namespace passed to XSD.exe in the ADO.NET application.

Imports XSDSchema.Namespace

The following code example uses a typed DataSet named CustomerDataSet to load a list of customers in the Northwind database. When the data is loaded using the Fill method, the example loops through each customer in the Customers table using a typed CustomersRow (DataRow) object. It provides direct access to CustomerID columns rather than through DataColumnCollection.

Dim customers As CustomerDataSet= New CustomerDataSet () Dim adapter As SqlDataAdapter New SqlDataAdapter (_ "SELECT * FROM dbo.Customers;", _ "Data Source= (local); Integrated" & _ "Security=SSPI;Initial Catalog=Northwind") adapter.Fill (customers, "Customers") Dim customerRow As CustomerDataSet.CustomersRow For Each customerRow In customers.Customers Console.WriteLine (customerRow.CustomerID) Next

The following is the ADO.NET XML schema used for this example.

Tags: Architecture tools generation code type instructions data examples syntax learning content customers applications instructions more programs spaces languages applications queries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Information Huawei MySQL Apple