asp.net<" />

2007年11月小记

系统 1140 0
1、使用SQL2005的XML类型分拆字符串。
DECLARE   @TagNames  XML;
SET   @TagNames   =   ' <?xml version="1.0" encoding="utf-8"?><ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><string>asp.net</string><string>sql</string><string>ajax</string></ArrayOfString> ' ;

DECLARE   @TagNameTable   TABLE ( [ IndexId ]   INT   IDENTITY ( 1 , 1 NOT   NULL   PRIMARY   KEY [ TagName ]   NVARCHAR ( 200 NOT   NULL )
    
INSERT   INTO   @TagNameTable
        
SELECT  tab.col.value( ' text()[1] ' , ' nvarchar(200) ' AS   [ TagName ]
        
FROM   @TagNames .nodes( ' /ArrayOfString/string ' AS  tab(col);

select   *   from   @TagNameTable   order   by   [ IndexId ]
2、使网页中所有链接都另页打开
< head >
    
< base  target ="_blank"   />
</ head >
3、Lambda表达式一例
         static   void  Main( string [] args)
        
{
            var strs 
=   new  List < string >   " A1 " " A2 " " A3 "  } ;
            List
< string >  list  =   new  List < string > ();

            
// 使用匿名委托
            strs.ForEach( delegate ( string  str)  { Console.WriteLine(str); } );

            
// 使用Lambda表达式
            strs.ForEach(x  =>  list.Add(x.TrimStart( ' A ' )));
            list.ForEach(x 
=>  Console.WriteLine(x));

            Console.ReadLine();
        }
4、WCF:ABC 从何地以何种方式绑定何种契约
5、如何成功调用 wsHttpBinding 邦定的WCF服务?
服务器定义了dns,如:
   < system .serviceModel >
    
< services >
      
< service  behaviorConfiguration ="passportServiceBehavior"  name ="CJB.Passport.Service.PassportService" >
        
< endpoint  address =""  binding ="wsHttpBinding"  contract ="CJB.Passport.Contract.IPassportService" >
          
< identity >
            
< dns  value ="localhost"   />
          
</ identity >
        
</ endpoint >
        
< endpoint  address ="mex"  binding ="mexHttpBinding"  contract ="IMetadataExchange"   />
      
</ service >
    
</ services >
    
< behaviors >
      
< serviceBehaviors >
        
< behavior  name ="passportServiceBehavior" >
          
< serviceMetadata  httpGetEnabled ="true"   />
          
< serviceDebug  includeExceptionDetailInFaults ="true"   />
        
</ behavior >
      
</ serviceBehaviors >
    
</ behaviors >
  
</ system.serviceModel >
客户端也要配置dns,此dns可以为服务器计算机名称,如:
     < system .serviceModel >
        
< client >
            
< endpoint  address ="http://passport2.ruiya.com/WcfService/PassportService.svc"
                binding
="wsHttpBinding"  bindingConfiguration =""  contract ="CJB.Passport.Contract.IPassportService"
                name
="iisHostEndpoint" >
                
< identity >
                    
< dns  value ="cjb" />
                
</ identity >
            
</ endpoint >
        
</ client >
    
</ system.serviceModel >
或者<dns value="localhost"/>
6、注意 between ... and ...在使用变量和使用拼接字符串中不过的执行计划导致的性能问题:
     declare   @handleTime   datetime ;
    
declare   @beginTime   datetime ;
    
declare   @endTime   datetime ;
    
set   @handleTime   =   DateAdd ( day - 1 getdate ());
    
set   @beginTime   =   CONVERT ( datetime CONVERT ( char ( 10 ),  @handleTime 120 ));
    
set   @endTime   =   DateAdd ( day 1 @beginTime );

    
declare   @sql   nvarchar ( 1000 );
    
set   @sql   =   ' SELECT * FROM [UserPosts] WITH(NOLOCK) WHERE ([AddTime] between  '''   +
        
cast ( @beginTime   as   nvarchar ( 100 ))  +   '''  AND  '''   +   cast ( @endTime   as   nvarchar ( 100 ))  +   ''' ) ' ;
    
-- print @sql
    
    
declare   @st   datetime
    
declare   @et   datetime

    
set   @st   =   getdate ();
    
exec ( @sql );
    
set   @et   =   getdate ();
    
select   datediff (millisecond,  @st @et );

    
set   @st   =   getdate ();
    
select   *   from   [ UserPosts ]   WITH (NOLOCK)  WHERE  ( [ AddTime ]   between   @beginTime   and   @endTime );
    
set   @et   =   getdate ();
    
select   datediff (millisecond,  @st @et );
拼接字符串: 0ms
使用变量: 23106 ms
7、SQL拆分字符串
CREATE   PROCEDURE   [ dbo ] . [ ec_System_SplitString ]
    
@strs   nvarchar ( 4000 ),
    
@separator   nchar ( 1 ) = ' , '
AS
BEGIN
    
SET  NOCOUNT  ON ;

    
DECLARE   @tbNames      table ( [ Name ]   nvarchar ( 256 NOT   NULL   PRIMARY   KEY )
    
DECLARE   @Num          int ;
    
DECLARE   @Pos          int ;
    
DECLARE   @NextPos      int ;
    
DECLARE   @Name          nvarchar ( 256 );
    
SET   @Num   =   0 ;
    
SET   @Pos   =   1 ;

    
WHILE ( @Pos   <=   LEN ( @strs ))
    
BEGIN
        
SELECT   @NextPos   =   CHARINDEX ( @separator @strs ,   @Pos )
        
IF  ( @NextPos   =   0   OR   @NextPos   IS   NULL )
            
SELECT   @NextPos   =   LEN ( @strs +   1
        
SELECT   @Name   =   RTRIM ( LTRIM ( SUBSTRING ( @strs @Pos @NextPos   -   @Pos )))
        
SELECT   @Pos   =   @NextPos + 1

        
        
INSERT   INTO   @tbNames   VALUES  ( @Name )
        
SET   @Num   =   @Num   +   1
    
END

    
SELECT   [ Name ]   FROM   @tbNames

END

2007年11月小记


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论