ASP.NET is immediately going to tutorial 11

xiaoxiao2021-03-05  28

Access XML-based data

The beginning of this chapter has been mentioned that DataSet is designed to abstract data from actual data sources. You can pass

Change the data in the instance to XML from SQL to XML. DataSet supports the READXML method, which uses FileStream

Objects as its parameters. In this case you read the files must contain (XML) plans and data to be read. Datas

ET expects data used in Form, as shown below:

Column Value

Column Value

Column Value

Column Value

Column Value

Column Value

Column Value

Column Value

Each TableName section corresponds to a line / one record in the table. The following example uses a DataSet's READXML method from XM

L File read plan and data. Note: When the data is read in DataSet, it is not different from SQL data.

DataGrid is binding it like binding SQL data, just like the following example:

C # datagrid17.aspx

[Run] | [Source Code]

You can also read the plan and data separately using DataSet's READXMLDATA and READXMLSCHEMA methods, like the following

example.

C # datagrid18.aspx

[Run] | [Source Code]

In addition to the way to read XML data, DataSet also supports writing XML data. The following example implements a tool

Used to query SQL data, write the result as XML data or plan text.

C # xmlgen.aspx

[Run] | [Source Code]

chapter summary

General Language Operation Time (CLR) Manages data access to extract and represent data in a consistent manner

Not relying on actual data sources, such as SQL Server, OLEDB, XML, and more.

In order to allow the ASP.NET page to access the SQL database, you must introduce System.Data and System.Data.s in the page.

Qlclient namespace. If you access the OLEDB database, you need to introduce System.Data and System.Data.OleDb names.

Space.

Space.

From the SQL query assembly data set (Dataset), including the SQLConnection, the associated SQLCONNECTION

QLDataAdapter object, then populate several steps of the DataSet with the Fill method of SqlDataAdapter.

The DataGrid control supports the DataSource property, which uses the IENUMERABLE or ICOLLECTION type. You can

Set these types to SQL query by assigning Dataset's DefaultView attributes (Type DataView)

result.

SqlDataAdapter contains a collection of parameters, which can replace the value to a variable flag (add one "@" before the name).

When performing a SQL command that does not return a result, such as insertion, update, and delete, you can use SqlCommand to replace SqlDataAd

APTER. The command is executed by calling ExecuteNonQuery method.

When using SQLCommand, you must open SQLConnection (SqlDataAdapter automatic processing open)

Pick up). Before the page is executed, I remember to turn off the SQLConnection. Otherwise, it will be handled in garbage collection function.

When the page instance is, I don't know, I don't know how to connect the connection.

In order to allow records to be edited, DataGrid supports an integer type EditIndex property, which can point out the form

Which line in it is edited. After setting this property, DataGrid will replace the text tag with the input box (ie, edit).

DataGrid provides a DatakeyField property that can set a field name for the primary key. Events bound in UpdateCommand

In the reason, you can get the name of the primary key from the data key collection of DataGrid.

The BoundColumn control in DataGrid allows you to fully control the status of the column, including the ReadOnly property.

Use the TemplateColumn control in DataGrid to make you fully control the contents of the column

ButtonColumn (button column) can be used to provide a button control in each line, which can be associated with events.

HyperLinkColumn (hyperlink column) can be added to the column set of DataGrid, when the link is clicked,

To orien to other pages.

When the DataGrid's AllowSorting is set to True, it provides hyperlinks in the column header location.

To activate the sort command and return to the form. When the user clicks this (used to sort) the link,

Event handle can be set in the DataGrid's OnSortCommand property.

DataSet supports READXML, READXMLDATA, and READXMLSCHEMA methods, using FileStream as parameters, it

Can be used to assemble Dataset from an XML file.

Using a stored procedure can reduce the load of the database in the application.

Since this part is much more, we use three chapters, including 9, 10 ,11, to serve the ASP.NET

The server is all finished. Starting from the later chapters, explain data access and user customization. Please look forward to ...

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

New Post(0)