Help C # rookos enter SQLXML development

xiaoxiao2021-03-06  116

What is XML? Many friends have a lot of theoretical knowledge, but how actually applied to development, it seems still a small problem. Today, a small example of initiators just reached, hoping to help those friends just get in touch with XML.

First of all, let's talk about our example - First, the database outputs XML and cut it in the .NET system.

The data layer of this system is to use the SQL Server database and the intermediate layer with SQL self-contained tool "Configuring SQL XML Support" in IIS. Ok, now we started to do it, first configure the SQL output XML:

This thing sounds like some mysterious, in fact, it is to increase after our ordinary query statement: for xml auto is OK.

for instance:

Select Top 100 Topic, Name, Time From Bbs Where [Order] = 1 Order by [TIME] Desc for XML AUTO

This statement is performed in the SQL query analyzer, everyone will find: The output is not the form of our traditional concept, is a few rows of strings, the content is what we need XML code.

In this way, let SQL output XML are completed.

Then start our step 2, let XML files can be called by web.

After this statement is debugged, you can build a file: such as aaa.xml

The content is as follows:

SELECT TOP 100 Topic, Name, Time From Bbs Where [Order] = 1 Order by [Time] desc for xml auto

In C: / create a BBB directory put him in.

The middle part is our traditional SQL statement, and if the front and rear packages are a format we are generally.

Put this file in a casual directory, then open SQL's "Configuring SQL XML Support in IIS" to create a virtual directory in a site that requires XML support, name is called CCC, local path is naturally our C: / BBB. Social security - enter your SQL to get your username and password, then the data source is your database location The default database. Then set, select Allow Template queries, then click the virtual name, point the new type is called DDD, the corresponding file is our AAA.xml.

Then open in IE: http: // What is your machine name / ccc / ddd? Yes, the content of your XML file is output when SQL query. What does not output? Open your "Internet Information Service (IIS) Manager", select "Web Extension Service", then select "All Unknown ISAP Extensions" Allow. Is it ok now?

Ok, then our most critical step 3 step - how to call this dynamically generated XML file in vs.net.

First we have to build an empty unstructured Dataset1, then in the source code in this.DataSet1.locale = new system.globalization.cultureInfo ("zh-cn"); then add a sentence this.DataSet1.Readxml ("http : // Your machine name / CCC / DDD ");

Congratulations, you can now use the dynamically generated XML file as a read-only DataSet.

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

New Post(0)