I. Access to XML data type SQL Server (SQL Server 2005 or 2008)
1. Store XML data into the database
Note:[Spprf] The type in dB is XML.
Sqlparameter sp = New Sqlparameter ();
Sp. sqldbtype = Sqldbtype. xml;
System. xml. xmlreader XR = System. xml. xmlreader. Create ( @" E: \ A. xml " );
String Strsqlconn = " ######### " ;
String Strselectsql = " Insert into [qauser] ([usrid], [uspwd], [spprf]) " ;
Strselectsql + = " Values ('test', '123', @ XML) " ;
Sqlconnection sqlconn = New Sqlconnection (strsqlconn );
Sqlcommand sqlcmd = New Sqlcommand (strselectsql, sqlconn );
Sqlcmd. Parameters. Add ( " @ XML " , Sqldbtype. XML). Value = XR;
Sqlconn. open ();
Sqlcmd. executenonquery ();
2. Retrieve XML
2. Bind XMLControls in ASP. NET
Use xmldatasource to dynamically load XML files and form different menus
Xmldatasource settings
< ASP: xmldatasource ID = "Xmlperformance1" Runat = "Server" Datafile = "~ /Test/xmlfile. xml" > </ ASP: xmldatasource >
Navigation File
<? XML version = "1.0" encoding = "UTF-8" ?>
< Menu Title = "Navigation" Description = "" >
< Menuitem URL = "Http://www.baidu.com" Title = "Netease" Description = "" />
< Menuitem URL = "Http://www.google.cn" Title = "Sina" Description = "" />
< Menuitem URL = "Http://www.163.com" Title = "126" Description = "" />
< Menuitem URL = "Http://www.126.com" Title = "Others" Description = "" />
</ Menu >
ASP: attribute definition in menu
< ASP: Menu ID = "Menu1" Runat = "Server" Orientation = "Horizontal" Performanceid = "Xmlperformance1"
Staticdisplaylevels = "2" >
< Databindings >
< ASP: menuitembinding Datamember = "Menu" Depth = "0" Textfield = "Title" />
< ASP: menuitembinding Datamember = "Menuitem" Depth = "1" Navigateurlfield = "Url" Textfield = "Title" />
</ Databindings >
</ ASP: Menu >
Xmldatasource settings
< ASP: xmldatasource ID = "Xmlperformance1" Runat = "Server" Datafile = "~ /Test/xmlfile. xml" > </ ASP: xmldatasource >
Navigation File
<? XML version = "1.0" encoding = "UTF-8" ?>
< Menu Title = "Navigation" Description = "" >
< Menuitem URL = "Http://www.baidu.com" Title = "Netease" Description = "" />
< Menuitem URL = "Http://www.google.cn" Title = "Sina" Description = "" />
< Menuitem URL = "Http://www.163.com" Title = "126" Description = "" />
< Menuitem URL = "Http://www.126.com" Title = "Others" Description = "" />
</ Menu >
ASP: attribute definition in menu
< ASP: Menu ID = "Menu1" Runat = "Server" Orientation = "Horizontal" Performanceid = "Xmlperformance1"
Staticdisplaylevels = "2" >
< Databindings >
< ASP: menuitembinding Datamember = "Menu" Depth = "0" Textfield = "Title" />
< ASP: menuitembinding Datamember = "Menuitem" Depth = "1" Navigateurlfield = "Url" Textfield = "Title" />
</ Databindings >
</ ASP: Menu >
Menuitembinding defines different layers and defines data sources for datamemeber. For example, the level in the first level of datamember is 0, and the level in the second level of data source is menuitem.
Since the first node is the root node, you do not need to set the naviateurlfield attribute.
The staticdisplaylevels attribute sets the maximum display level at the beginning of display.