ʹÓÃXMLÔÚSQL ServerÉÏ´´½¨¼ÆËãÁÐ
¡¡ÔÚSQL ServerÊý¾Ý¿âÖУ¬µ±ÄãÏëʹÓÃÒ»¸öÊý¾Ý£¬¶øÕâ¸öÊý¾Ý²»±£´æÔÚ±íÖУ¬¼ÆËãÁкÜÓÐÓá£ÀýÈ磬ÄãÓÐÒ»ÕÅ±í£¬Ëü°üÀ¨ÁÐdollar amounts, wholesale pricesºÍretail prices¡£Äã¿Ï¶¨²»ÏëÔÚÿ´Î²éѯ±íʱÀ´¼ÆËãÄÇÁ½ÁÐÖ®¼äµÄ²îÖµ£¬ÄãÏ£Íû½«ÆäÖµ±£´æÔÚµÚÈýÁÐÖУ¬ÈÃÆä×Ô¶¯¼ÆËãÇ°Á½ÁÐÖ®¼äµÄ²îÖµ¡£¶ø´ËÁоÍÊǼÆËãÁС£
¡¡¡¡ÔÚSQL ServerÖÐʹÓÃXMLÊý¾ÝÀ´´´½¨¼ÆËãÁУ¬ÄãµÄÁж¨Òå±ØÐë°üº¬±ØÒªµÄÓÃÀ´¼ì²âÏòÁÐÖвåÈëµÄÊÇʲôÊý¾ÝµÄ±í´ïʽ¡£ÀýÈ磬ÔÚÉÏÃæµÄÀý×ÓÖУ¬ÄãµÄ±í´ïʽӦ¸Ã´ÓretailÁÐÖеÄÖµ¼õÈ¥wholesaleÁÐÖеÄÖµ¡£µ±ÄãÌí¼Ó»ò¸üбíÖеÄÊý¾ÝÐÐʱ£¬²îÖµ½«×Ô¶¯²åÈëÖÁ¼ÆËãÁÐÖС£
¡¡¡¡Äã¿ÉÒÔºÜÈÝÒ×µØÔÚÁ½¸ö»ò¸ü¶àµÄ°üº¬×Ö·û´®»òÊý×ÖÀàÐÍÖµµÄÁеĻù´¡ÉÏ´´½¨¼ÆËãÁС£(¸ü¶à¹ØÓÚÈçºÎ´´½¨´ËÀàÐ͵ļÆËãÁеÄÏêϸÐÅÏ¢£¬Çë²Î¿¼Microsoft SQL Server Books Online)¡£È»¶ø£¬Èç¹ûÄãÏëÒª»ùÓÚÖ¸¶¨µÄXMLÁÐÖÐÔªËØÖµ´´½¨Ò»¸ö¼ÆËãÁУ¬¸Ã¹ý³ÌÏà¶Ô¸ü¼Ó¸´ÔÓһЩ¡£ÒòΪÄã±ØÐëʹÓÃXquery±í´ïʽÀ´´ÓXMLÁÐÖлñÈ¡Ö¸¶¨ÔªËØÊý¾Ý,ÇÒSQL Server²»Ö§³ÖÔÚ¼ÆËãÁеĶ¨ÒåÖÐʹÓÃXquery±í´ïʽ¡£
¡¡¡¡Òª½â¾ö´ËÎÊÌ⣬¿ÉÒÔ´´½¨Ò»¸öº¯ÊýÀ´½ÓÊÕÄãÏë°üº¬ÔÚ¼ÆËãÁÐÖеÄXMLÊý¾Ý£¬²¢ÔÚ¼ÆËãÁж¨ÒåÖе÷Óô˺¯Êý¡£¸üºÃµÄʾ·¶ÕâÊÇÈçºÎ¹¤×÷µÄ£¬ÎÒÃÇÔÚÕâ¸ø³öÒ»¸öÀý×Ó¡£ÎÒÔÚSQL Server 2005µÄʾÀýÊý¾Ý¿âAdventureWorksÖд´½¨ÒÔϵļܹ¹ºÍ±í:
¡¡¡¡USE AdventureWorks;
¡¡¡¡GO
¡¡¡¡CREATE SCHEMA hr
¡¡¡¡GO
¡¡¡¡SELECT TOP 10 JobCandidateID AS CandidateID,
¡¡¡¡[Resume] AS JobResume
¡¡¡¡INTO hr.CandidateNames
¡¡¡¡from HumanResources.JobCandidate
¡¡¡¡GO
¡¡¡¡ÕýÈçÃû³ÆËùʾ£¬HumanResources.JobCandidate±íÖеÄResumeÁÐÊÇÒ»¸öXMLÁУ¬Ëü°üº¬ºîÑ¡È˵ÄÂÄÀúÐÅÏ¢¡£ÎÒ´ÓÕâÕűíÖÐÌáÈ¡Êý¾ÝÀ´´´½¨hr¼Ü¹¹ÖеÄCandidateNames±í¡£(ÎÒ´´½¨ÁËÒ»¸öµ¥¶ÀµÄ±í£¬ÒòΪÎÒÏ£Íû¿ÉÒÔÐÞ¸Ä±í¶¨Ò壬´Ó¶ø¿ÉÒÔÔö¼Ó¼ÆËãÁÐ) ÔÚ½¨Á¢ºÃ²âÊÔ»·¾³ºó£¬Äã¿ÉÒÔ´´½¨º¯Êý¡£º¯ÊýÓ¦¸Ã°üÀ¨ÔÚ´ÓÖ¸¶¨µÄXMLÁÐÖлñÈ¡Êý¾ÝʱËùÐèµÄXQuery±í´ïʽ¡£ÀýÈ磬ÒÔϺ¯Êý½ÓÊÕ¹¤×÷ºòÑ¡È˵ÄÐÕÃû£¬²¢±£´æÔÚJobResumeÁÐÖУº
¡¡¡¡CREATE FUNCTION hr.FullName (@name XML)
¡¡¡¡RETURNS NVARCHAR(60) AS
¡¡¡¡BEGIN
¡¡¡¡RETURN @name.value('declare namespace ns=
¡¡¡¡"http://schemas.microsoft.com/sqlserver/2004/07/adventure-
¡¡¡¡works/Resume";
¡¡¡¡concat((/ns:Resume/ns:Name/ns:Name.First)[1], " ",
¡¡¡¡(/ns:Resume/ns:Name/ns:Name.Last)[1])','nvarchar(
Ïà¹ØÎĵµ£º
<!-- xml ¸ñʽ
<books>
<book id='1001'>
<author>andylin</author>
<title>c language</title>
<publisher id="aaa">O'Reilly</publisher>
</book>
<book id='1002'>
<author>congfeng</author>
<t ......
ͨ³£ÔÚ²Ù×÷xmlµÄʱºò£¬¶¼ÊÇͨ¹ýinputstream£¨ºÜ¶àÇé¿öÏÂÊÇFileInputStream£©À´¶ÁÈëxml²¢×ªÎªdomµÄ£¬ºÜ¶àÈË»áÓöµ½ÕâÖÖÇé¿öÊý¾Ý²»ÊÇ´ÓÎļþ¶ÁÈëµÄ¶øÊÇ´ÓStringÖÐÈ¡µÃµÄ
ÓÚÊÇ»áʹÓÃ
InputStream in = new ByteArrayInputStream (str.getBytes());À´È¡µÃinputstream £¬µ«ÊÇÕâÖÖInputStreamÖÐÊý¾Ý±»×ª³ÉÁËbyteÊý×飬ËùÒÔתdom ......
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
//µ¼ÈëʹÓÃxmlÓ¦ÓÃËùÐèµ ......
ÔÚʹÓÃsqlserver2005´´½¨×÷ҵʱ£¬´´½¨²»ÁË£¬Ìáʾ
ÎÞ·¨½«ÀàÐÍΪ“Microsoft.SqlServer.Management.Smo.SimpleObjectKey”µÄ¶ÔÏóÇ¿ÖÆת»»ÎªÀàÐÍ“Microsoft.SqlServer.Management.Smo.Agent.JobObjectKey”¡£ (Microsoft.SqlServer.Smo)
ÓÚÊǾÍgoogle£¬°Ù¶ÈÁËһϣ¬ºÃ¶àÎÄÕºÍÌù×Ó˵ÐèÒª° ......
SQL Native Client ODBC Driver
±ê×¼°²È«Á¬½Ó
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
ÄúÊÇ·ñÔÚʹÓÃSQL Server 2005 Express ÇëÔÚ“Server”Ñ¡ÏîʹÓÃÁ¬½Ó±í´ïʽ“Ö÷»úÃû³Æ\SQLEXPRESS”¡£
ÊÜÐŵÄÁ¬½Ó
Driver={SQL Native ......