Writing and Reading XML Using a DataSet Object

Writing and Reading XML Using a DataSet Object XML is a convenient format for moving information around. You can write out the contents of the DataTable objects contained in a DataSet to an XML file using the WriteXml() method | Writing and Reading XML Using a DataSet Object XML is a convenient format for moving information around. You can write out the contents of the DataTable objects contained in a DataSet to an XML file using the WriteXml method. The XML file written by this method contains the DataTable column names and values. You can write out the schema of a DataSet object to an XML file using the WriteXmlSchema method. The XML file written by this method contains the structure of the DataTable objects contained in the DataSet. You can also get the XML in a DataSet using the GetXml method which returns the XML in a string. You can read the contents of the DataTable objects in an XML file into a DataSet using the ReadXml method. You can also read the schema contained in an XML file using the ReadXmlSchema method. Note SQL Server also contains extensive built-in XML functionality which you ll learn about in Chapter 16 Using SQL Server s XML Support. Using the WriteXml Method Let s say you have a DataSet object named myDataSet. Assume that myDataSet has a DataTable that contains the CustomerID CompanyName ContactName and Address columns for the top two rows from the Customers table. The following code shows this SqlCommand mySqlCommand SELECT TOP 2 CustomerID CompanyName ContactName Address FROM Customers ORDER BY CustomerID SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlCommand DataSet myDataSet new DataSet Retrieving rows from the Customers table myDataSet Customers You can write out the contents of myDataSet to an XML file using the WriteXml method. For example This writes an XML file named as shown in Listing . xml version standalone yes NewDataSet Customers CustomerID ALFKI CustomerID .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU LIÊN QUAN
5    176    1
5    255    1
5    106    0
5    121    1
6    103    1
6    107    1
6    121    1
6    103    0
6    140    0
6    98    0
TÀI LIỆU MỚI ĐĂNG
24    20    1    29-11-2024
272    23    1    29-11-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.