tailieunhanh - Saving and Loading a DataSet from XML

[ Team LiB ] Recipe Saving and Loading a DataSet from XML Problem You need to save a DataSet as an XML file and create a DataSet from an XML file. Solution Use the XmlTextWriter and XmlTextReader classes. The sample code contains three event handlers | Team LiB Recipe Saving and Loading a DataSet from XML Problem You need to save a DataSet as an XML file and create a DataSet from an XML file. Solution Use the XmlTextWriter and XmlTextReader classes. The sample code contains three event handlers Write Creates a DataSet containing the Orders and Order Details tables from Northwind and a relation between the two tables. The XML schema and data for the DataSet is written both to a file and to a text box on the form. Read Creates a DataSet and reads in schema and data from a file containing a previously serialized XML. The XML is written from the DataSet to a stream and displayed. Clear Clears the data grid and the result text box. The C code is shown in Example 8-3. Example 8-3. File Namespaces variables and constants using System using using using using using using using using Table name constants private const String ORDERS_TABLE Orders private const String ORDERDETAILS_TABLE OrderDetails Relation name constants private const String ORDERS_ORDERDETAILS_RELATION Orders_OrderDetails_Relation Field name constants private const String ORDERID_FIELD OrderlD . . . private void writeXmlButton_Click object sender e DataSet ds new DataSet SqlDataAdapter da Fill the Order table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString DataTable orderTable new DataTable ORDERS_TABLE orderTable orderTable orderTable Fill the OrderDetails table and add it to the DataSet. da new SqlDataAdapter SELECT FROM Order Details S ql_ConnectString DataTable orderDetailTable new DataTable ORDERDETAILS_TABLE orderDetailTable orderDetailTable .

crossorigin="anonymous">
Đã 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.