zoukankan      html  css  js  c++  java
  • 2008年6月小记

    1、SP拆分字符串,如把a1,a2,a3以,分隔拆分出来
    ALTER PROCEDURE [dbo].[ec_System_SplitString]
        
    @strs nvarchar(4000),
        
    @separator nchar(1)=','
    AS
    BEGIN
        
    SET NOCOUNT ON;

        
    DECLARE @tbNames    table([Name] nvarchar(256NOT 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

    2、在IIS7中如何继续使用URLRewriterApplicationErrorLog
    <system.web>中配置也要在<system.webServer>中添加一份
    如有如下的配置
    <system.web>
        
    <httpModules>
            
    <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
        
    </httpModules>
    </system.web>
    同时也应该在<system.webServer>中添加一份
    <system.webServer>
        
    <modules>
            
    <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
        
    </modules>
    </system.webServer>
    ApplicationErrorLog配置
    <system.web>
        
    <httpHandlers>
            
    <add verb="POST,GET,HEAD" path="ErrorLog.aspx" type="Lion.Web.ApplicationErrorLog.ErrorLogPageFactory, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        
    </httpHandlers>
        
    <httpModules>
            
    <add name="ErrorLog" type="Lion.Web.ApplicationErrorLog.ErrorLogModule, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        
    </httpModules>
    </system.web>
    <system.webServer>
        
    <handlers>
            
    <add name="ApplicationErrorLog" verb="POST,GET,HEAD" path="ErrorLog.aspx" type="Lion.Web.ApplicationErrorLog.ErrorLogPageFactory, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        
    </handlers>
        
    <modules>
            
    <add name="ErrorLog" type="Lion.Web.ApplicationErrorLog.ErrorLogModule, Lion.Web.ApplicationErrorLog, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
        
    </modules>
    </system.webServer>

    3、去除IIS7的30MB上传限制
    修改文件C:\Windows\System32\inetsrv\config\schema\IIS_schema.xml
    <attribute name="maxAllowedContentLength" type="uint" defaultValue="30000000" />
    加个0就是300MB

    4、通过子类构建父类
    public class RecordHistory : RecordMetadata

            private RecordHistory CopyToRecordHistory(RecordMetadata metadata)
            
    {
                
    //使用反射把RecordMetadata导入到RecordHistory
                RecordHistory history = null;

                
    if (metadata != null)
                
    {
                    history 
    = new RecordHistory();

                    Type historyType 
    = history.GetType();
                    Type metadataType 
    = metadata.GetType();

                    PropertyInfo[] historyProperties 
    = historyType.GetProperties();
                    
    foreach (PropertyInfo historyProperty in historyProperties)
                    
    {
                        PropertyInfo metadataProperty 
    = metadataType.GetProperty(historyProperty.Name);
                        
    if (metadataProperty != null)
                        
    {
                            metadataProperty.SetValue(history, metadataProperty.GetValue(metadata, 
    null), null);
                        }

                    }

                }


                
    return history;
            }

    5、Linq to SQL中如何解决"Specified cast is not valid"的问题
    在使用Linq to SQL中对象属性与数据库中表字段的类型转换无效的问题 ,例如:数据表字段Audit的类型为tinyint,它对应的对象是
        [Column(Name = "Audit")]
            
    public Int16 Audit { getset; }
    但是这样在query时会出现"Specified cast is not valid"的错误,其实这是在定义DataContext对象时没有指定DbType所致,所以定义可以改为
            [Column(Name = "Audit", DbType = "tinyint")]
            
    public Int16 Audit { getset; }

    6、
    异步调用asmx的Web方法
    引用asmx页面,VS会自动生成代理,除了原生的方法外例如PingPost,还会自动生PingPostAsync这样以Async尾的相对应异常调用方法,不过使用这个异步方法的页面还是需要设置一下
    <%@ Page  Async="true"  %>

    7、SQL常用语句收集

    8、判断一个js对象是否未定义:if(typeof(kk) == 'undefined')

    9、使用UriBuilder移除url参数
            Response.Output.Write(new UriBuilder(Request.Url)
            {
                 Query
    =null
            }.ToString());

    http://localhost:46630/CSDN.ExpertCenter.WebTest/Demos/B.aspx?username=billok&count=12  ==>
    http://localhost:46630/CSDN.ExpertCenter.WebTest/Demos/B.aspx
    通过扩展UriBuilder类来增强功能的类还有UrlBuilder
    另外:VirtualPathUtility 类为涉及虚拟路径的常见操作提供实用工具方法。
    VirtualPathUtility.IsAppRelative 判断是否为虚拟路径.
    HttpRuntime 和 HostingEnvironment 都是很实用的辅助工具。
    Path.IsPathRooted 判断是不是为绝对路径

    if (!Path.IsPathRooted(path))
      path 
    = HttpContext.Current.Server.MapPath(path);



    10、将访问Windows文件夹变为磁盘盘符

    11、通过FileIOPermission进行代码访问权限检测

    FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Read,@"c:\billchen.txt");
    permission.Demand();

    12、使用StringComparer创建大小写无关的字典:
    Dictionary<stringint> dic = new Dictionary<stringint>(StringComparer.InvariantCultureIgnoreCase);
    dic[
    "Test"= 10;
    int n = dic["test"];

    13、排重表的重复行
    select a.username,a.tagname,a.tagtype into  temp
        
    from usertags a 
        
    group by a.username,a.tagname,a.tagtype

    truncate table UserTags

    insert into UserTags(username,tagname,tagtype)
    select username,tagname,tagtype
    from temp

    drop table temp




  • 相关阅读:
    EntityFramework之领域驱动设计实践
    Entity Framework 学习初级篇1EF基本概况(入门)
    整理一下Entity Framework的查询
    Unity(六):使用场景Ⅲ:用于依赖注入(上)
    比较NHibernate和Entity Framework
    contentclass对应的一些值
    IE8访问架设在Windows Server 2008(R2)的SharePoint Server 2007是验证框问题
    创建一个图文并茂的调查
    SharePoint回环检查(Loopback Check)相关问题
    Something you need to know about Content Deployment in SharePoint
  • 原文地址:https://www.cnblogs.com/chenjunbiao/p/1760210.html
Copyright © 2011-2022 走看看