Storing XML to a Database Field

[ Team LiB ] Recipe 8. Storing XML to a Database Field Problem You need to store XML to a field in a database. Solution Store the contents of the InnerXml of the XmlDocument to the database. You can later load this into an empty XmlDocument with LoadXml( ). | Team LiB Recipe 8. Storing XML to a Database Field Problem You need to store XML to a field in a database. Solution Store the contents of the InnerXml of the XmlDocument to the database. You can later load this into an empty XmlDocument with LoadXml . The schema of table TBL0804 used in this solution is shown in Table 8-4. Table 8-4. TBL0804 schema Column name Data type Length Allow nulls Id int 4 No XmlField nvarchar 4000 Yes The sample code contains five event handlers Sets up the DataTable that contains the text field XmlField containing the XML and the DataAdapter for the table. Write Adds or updates a record in the table with the Id and XmlField entered by the user. Read Loads the XML for the specified Id into an XmlDocument and displays it on the form in the XmlField text box. Sample Generates sample XML data from the Orders table in Northwind and displays it on the form in the XmlField text box. Clear Clears the contents of the Id and XmlField text boxes on the form. The C code is shown in Example 8-7. Example 8-7. File Namespaces variables and constants using System using using using using using using private DataTable dt private SqlDataAdapter da private const String TABLENAME TBL0804 . . . private void StoreXmlFieldForm_Load object sender e String selectText SELECT Id XmlField FROM TABLENAME String insertText INSERT TABLENAME Id XmlField VALUES @Id @XmlField String updateText UPDATE TABLENAME SET XmlField @XmlField WHERE Id @Id Create the data adapter. da new SqlDataAdapter selectText S ql_ConnectString new SqlCommand updateText @Id 0 Id @XmlField .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã 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.