Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Linq to XML customize distinct function

Definition comparer class,
class ItemComparer : IEqualityComparer<XElement>
{
public bool Equals(XElement x, XElement y)
{
return x.Attribute("Name").Value == x.Attribute("Name").Value;
}
public int GetHashCode(XElement obj)
{
return obj.Attribute("Name").Value.GetHashCode();
}
}
How to use this one to distinct:
public List<string> LoadDistrict(string region)
{
if (m_DataDoc == null)
return null;
List<string> list = new List<string>();
try
{
var query = from r in m_DataDoc.Elements("DashBoardData").Elements("LevelData").Elements("Region").Where(a => a.Attribute("Name").Value.ToLower() == region.ToLower())
select r;
foreach (var district in query.Elements("District").Distinct(new ItemComparer()))
{
list.Add(district.Attribute("Name").Value);
}
return list;
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
return null;
}
}


Ïà¹ØÎĵµ£º

ʹÓÃXmlDocumentÀàÍê³É¶ÔXMLµÄ²é¡¢É¾¡¢Ìí¡¢¸Ä

ʹÓÃXmlDocumentÀàÍê³É¶ÔXMLµÄ²é¡¢É¾¡¢Ìí¡¢¸Ä
http://www.aspdiy.net/article/53.htm
ºǫ́C#´úÂë
  1using System;
  2using System.Collections;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System. ......

xmlÌØÊâ×Ö·û¶¨Òå

   XML¿ª·¢ÈëÃÅ»ù´¡£ºXMLÓï·¨¹æÔò(2) - ÍøÒ³Éè¼ÆרÀ¸ - ±à³ÌÈëÃÅÍø
     http://www.bianceng.cn/web/XML/200911/11986_2.htm
   
   ×Ö·û          ʵÌåÒýÓÃ
    >   &n ......

XMLÐòÁл¯(Ò»)

MSDNÉϵĶ¨Ò壺
XML ÐòÁл¯½«¶ÔÏóµÄ¹«¹²×ֶκÍÊôÐÔ»òÕß·½·¨µÄ²ÎÊýºÍ·µ»Øֵת»»£¨ÐòÁл¯£©Îª·ûºÏÌض¨ XML ¼Ü¹¹¶¨ÒåÓïÑÔ (XSD) ÎĵµµÄ XML Á÷¡£XML ÐòÁл¯Éú³ÉÇ¿ÀàÐ͵ÄÀ࣬²¢Îª´æ´¢»ò´«ÊäÄ¿µÄ½«Æ乫¹²ÊôÐÔºÍ×Ö¶Îת»»ÎªÐòÁиñʽ£¨ÔÚ´ËÇé¿öÏÂΪ XML)¼òµ¥µÄ˵¾ÍÊǽ«Ò»¸ö¶ÔÏóת»»³ÉXMLÁ÷»òÊÇÎļþµÄ¹ý³Ì¡£
×¢ÒâÊÂÏҪÐòÁл¯µÄÀ ......

xml ÐÎʽµÄ´æ´¢¹ý³Ì

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
create procedure [dbo].[MachiningPayedGetListByCondition]
@CustomerName varchar(50),
@CustomerPhone varchar(50),
@PactNumber varchar(50),
@Ispay bit
as
begin
 set nocount on;
 SELECT
 dp.ID as 'MachiningPayed/@ID',
&nbs ......

ʹÓÃSQL²Ù×÷XML¼òµ¥Ê¾Àý

declare @xml xml
set @xml = '<root/>'
select @xml
declare @value varchar(10)
set @value = 'val1'
set @xml.modify('insert <item value="{sql:variable("@value")}" /> into (/root)[1]')
select @xml
set @value = 'val2'
set @xml.modify('replace value of (/root/item/@value)[1] with "val2 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ