﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>博客园-Lileltp's Blog</title><link>http://www.cnblogs.com/Lileltp/</link><description /><language>zh-cn</language><lastBuildDate>Wed, 10 Feb 2010 07:48:58 GMT</lastBuildDate><pubDate>Wed, 10 Feb 2010 07:48:58 GMT</pubDate><ttl>60</ttl><item><title>[转载]泛型与泛型集合</title><link>http://www.cnblogs.com/Lileltp/archive/2009/07/16/1525053.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Thu, 16 Jul 2009 09:25:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2009/07/16/1525053.html</guid><description><![CDATA[<p>阅读: 24 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2009-07-16 17:25 <a href="http://www.cnblogs.com/Lileltp/archive/2009/07/16/1525053.html" target="_blank">原文链接</a></p><p>不好意思忘了出处。老早就copy到了witer里。</p>  <p>在2005年底微软公司正式发布了C# 2.0，与C# 1.x相比，新版本增加了很多新特性，其中最重要的是对泛型的支持。通过泛型，我们可以定义类型安全的数据结构，而无需使用实际的数据类型。这能显著提高性能并得到更高质量的代码。泛型并不是什么新鲜的东西，他在功能上类似于C++的模板，模板多年前就已存在C++上了，并且在C++上有大量成熟应用。 </p>  <p>&#160;&#160;&#160; 本文讨论泛型使用的一般问题，比如为什么要使用泛型、泛型的编写方法、泛型中数据类型的约束、泛型中静态成员使用要注意的问题、泛型中方法重载的问、泛型方法等，通过这些使我们可以大致了解泛型并掌握泛型的一般应用，编写出更简单、通用、高效的应用系统。</p>  <p>&#160;&#160;&#160; 什么是泛型</p>  <p>&#160;&#160;&#160; 我们在编写程序时，经常遇到两个模块的功能非常相似，只是一个是处理int数据，另一个是处理string数据，或者其他自定义的数据类型，但我们没有办法，只能分别写多个方法处理每个数据类型，因为方法的参数类型不同。有没有一种办法，在方法中传入通用的数据类型，这样不就可以合并代码了吗？泛型的出现就是专门解决这个问题的。读完本篇文章，你会对泛型有更深的了解。</p>  <p>&#160;&#160;&#160; 为什么要使用泛型</p>  <p>为了了解这个问题，我们先看下面的代码，代码省略了一些内容，但功能是实现一个栈，这个栈只能处理int数据类型：</p>  <pre><span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> Stack

    { 
        <span style="color: #0000ff">private</span> <span style="color: #0000ff">int</span>[] m_item;
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">int</span> Pop(){...} 
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Push(<span style="color: #0000ff">int</span> item){...} 
        <span style="color: #0000ff">public</span> Stack(<span style="color: #0000ff">int</span> i)
        {
            <span style="color: #0000ff">this</span>.m_item = <span style="color: #0000ff">new</span> <span style="color: #0000ff">int</span>[i];
        }
}</pre>

<p>上面代码运行的很好，但是，当我们需要一个栈来保存string类型时，该怎么办呢？很多人都会想到把上面的代码复制一份，把int改成string不就行了。当然，这样做本身是没有任何问题的，但一个优秀的程序是不会这样做的，因为他想到若以后再需要long、Node类型的栈该怎样做呢？还要再复制吗？优秀的程序员会想到用一个通用的数据类型object来实现这个栈：</p>

<p>public class Stack</p>

<p>&#160;&#160;&#160; { </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private object[] m_item;</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public object Pop(){...} </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void Push(object item){...} </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public Stack(int i)</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.m_item = new[i];</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>

<p>&#160;&#160;&#160; }</p>

<p>这个栈写的不错，他非常灵活，可以接收任何数据类型，可以说是一劳永逸。但全面地讲，也不是没有缺陷的，主要表现在：</p>

<p>当Stack处理值类型时，会出现装箱、折箱操作，这将在托管堆上分配和回收大量的变量，若数据量大，则性能损失非常严重。 </p>

<p>在处理引用类型时，虽然没有装箱和折箱操作，但将用到数据类型的强制转换操作，增加处理器的负担。 </p>

<p>在数据类型的强制转换上还有更严重的问题（假设stack是Stack的一个实例）：</p>

<p>Node1 x = new Node1();</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; stack.Push(x);</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Node2 y = (Node2)stack.Pop();</p>

<p>上面的代码在编译时是完全没问题的，但由于Push了一个Node1类型的数据，但在Pop时却要求转换为Node2类型，这将出现程序运行时的类型转换异常，但却逃离了编译器的检查。</p>

<p>针对object类型栈的问题，我们引入泛型，他可以优雅地解决这些问题。泛型用用一个通过的数据类型T来代替object，在类实例化时指定T的类型，运行时（Runtime）自动编译为本地代码，运行效率和代码质量都有很大提高，并且保证数据类型安全。</p>

<p>使用泛型</p>

<p>下面是用泛型来重写上面的栈，用一个通用的数据类型T来作为一个占位符，等待在实例化时用一个实际的类型来代替。让我们来看看泛型的威力：</p>

<p>public class Stack&lt;T&gt;</p>

<p>&#160;&#160;&#160; { </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; private T[] m_item;</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public T Pop(){...} </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void Push(T item){...} </p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public Stack(int i)</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.m_item = new T[i];</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; } </p>

<p>}</p>

<p>类的写法不变，只是引入了通用数据类型T就可以适用于任何数据类型，并且类型安全的。这个类的调用方法：</p>

<p>//实例化只能保存int类型的类</p>

<p>Stack&lt;int&gt; a = new Stack&lt;int&gt;(100);</p>

<p>&#160;&#160;&#160;&#160;&#160; a.Push(10);</p>

<p>&#160;&#160;&#160;&#160;&#160; a.Push(&quot;8888&quot;); //这一行编译不通过，因为类a只接收int类型的数据</p>

<p>&#160;&#160;&#160;&#160;&#160; int x = a.Pop();</p>

<p>//实例化只能保存string类型的类</p>

<p>Stack&lt;string&gt; b = new Stack&lt;string&gt;(100);</p>

<p>b.Push(10);&#160;&#160;&#160; //这一行编译不通过，因为类b只接收string类型的数据</p>

<p>&#160;&#160;&#160;&#160;&#160; b.Push(&quot;8888&quot;);</p>

<p>&#160; string y = b.Pop();</p>

<p>这个类和object实现的类有截然不同的区别：</p>

<p>1.&#160;&#160;&#160;&#160;&#160;&#160; 他是类型安全的。实例化了int类型的栈，就不能处理string类型的数据，其他数据类型也一样。</p>

<p>2.&#160;&#160;&#160;&#160;&#160;&#160; 无需装箱和折箱。这个类在实例化时，按照所传入的数据类型生成本地代码，本地代码数据类型已确定，所以无需装箱和折箱。</p>

<p>3.&#160;&#160;&#160;&#160;&#160;&#160; 无需类型转换。</p>

<p>泛型类实例化的理论</p>

<p>C#泛型类在编译时，先生成中间代码IL，通用类型T只是一个占位符。在实例化类时，根据用户指定的数据类型代替T并由即时编译器（JIT）生成本地代码，这个本地代码中已经使用了实际的数据类型，等同于用实际类型写的类，所以不同的封闭类的本地代码是不一样的。按照这个原理，我们可以这样认为：</p>

<p>泛型类的不同的封闭类是分别不同的数据类型。</p>

<p>例：Stack&lt;int&gt;和Stack&lt;string&gt;是两个完全没有任何关系的类，你可以把他看成类A和类B，这个解释对泛型类的静态成员的理解有很大帮助。</p>

<p>泛型类中数据类型的约束</p>

<p>程序员在编写泛型类时，总是会对通用数据类型T进行有意或无意地有假想，也就是说这个T一般来说是不能适应所有类型，但怎样限制调用者传入的数据类型呢？这就需要对传入的数据类型进行约束，约束的方式是指定T的祖先，即继承的接口或类。因为C#的单根继承性，所以约束可以有多个接口，但最多只能有一个类，并且类必须在接口之前。这时就用到了C#2.0的新增关键字：</p>

<p>public class Node&lt;T, V&gt; where T : Stack, IComparable</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; where V: Stack</p>

<p>&#160;&#160;&#160; {...}</p>

<p>以上的泛型类的约束表明，T必须是从Stack和IComparable继承，V必须是Stack或从Stack继承，否则将无法通过编译器的类型检查，编译失败。</p>

<p>通用类型T没有特指，但因为C#中所有的类都是从object继承来，所以他在类Node的编写中只能调用object类的方法，这给程序的编写造成了困难。比如你的类设计只需要支持两种数据类型int和string，并且在类中需要对T类型的变量比较大小，但这些却无法实现，因为object是没有比较大小的方法的。了解决这个问题，只需对T进行IComparable约束，这时在类Node里就可以对T的实例执行CompareTo方法了。这个问题可以扩展到其他用户自定义的数据类型。</p>

<p>如果在类Node里需要对T重新进行实例化该怎么办呢？因为类Node中不知道类T到底有哪些构造函数。为了解决这个问题，需要用到new约束：</p>

<p>public class Node&lt;T, V&gt; where T : Stack, new()</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; where V: IComparable</p>

<p>需要注意的是，new约束只能是无参数的，所以也要求相应的类Stack必须有一个无参构造函数，否则编译失败。</p>

<p>C#中数据类型有两大类：引用类型和值类型。引用类型如所有的类，值类型一般是语言的最基本类型，如int, long, struct等，在泛型的约束中，我们也可以大范围地限制类型T必须是引用类型或必须是值类型，分别对应的关键字是class和struct:</p>

<p>public class Node&lt;T, V&gt; where T : class</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; where V: struct</p>

<p>泛型方法</p>

<p>泛型不仅能作用在类上，也可单独用在类的方法上，他可根据方法参数的类型自动适应各种参数，这样的方法叫泛型方法。看下面的类：</p>

<p>public class Stack2</p>

<p>&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void Push&lt;T&gt;(Stack&lt;T&gt; s, params T[] p)</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; foreach (T t in p)</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; s.Push(t);</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>

<p>}</p>

<p>原来的类Stack一次只能Push一个数据，这个类Stack2扩展了Stack的功能（当然也可以直接写在Stack中），他可以一次把多个数据压入Stack中。其中Push是一个泛型方法，这个方法的调用示例如下：</p>

<p>Stack&lt;int&gt; x = new Stack&lt;int&gt;(100);</p>

<p>&#160;&#160;&#160; Stack2 x2 = new Stack2();</p>

<p>&#160;&#160;&#160; x2.Push(x, 1, 2, 3, 4, 6);</p>

<p>&#160;&#160;&#160; string s = &quot;&quot;;</p>

<p>&#160;&#160;&#160; for (int i = 0; i &lt; 5; i++)</p>

<p>&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; s += x.Pop().ToString();</p>

<p>&#160;&#160;&#160; }&#160;&#160;&#160; //至此，s的值为64321</p>

<p>泛型中的静态成员变量</p>

<p>在C#1.x中，我们知道类的静态成员变量在不同的类实例间是共享的，并且他是通过类名访问的。C#2.0中由于引进了泛型，导致静态成员变量的机制出现了一些变化：静态成员变量在相同封闭类间共享，不同的封闭类间不共享。</p>

<p>这也非常容易理解，因为不同的封闭类虽然有相同的类名称，但由于分别传入了不同的数据类型，他们是完全不同的类，比如：</p>

<p>Stack&lt;int&gt; a = new Stack&lt;int&gt;();</p>

<p>Stack&lt;int&gt; b = new Stack&lt;int&gt;();</p>

<p>Stack&lt;long&gt; c = new Stack&lt;long&gt;();</p>

<p>类实例a和b是同一类型，他们之间共享静态成员变量，但类实例c却是和a、b完全不同的类型，所以不能和a、b共享静态成员变量。</p>

<p>泛型中的静态构造函数</p>

<p>静态构造函数的规则：只能有一个，且不能有参数，他只能被.NET运行时自动调用，而不能人工调用。</p>

<p>泛型中的静态构造函数的原理和非泛型类是一样的，只需把泛型中的不同的封闭类理解为不同的类即可。以下两种情况可激发静态的构造函数：</p>

<p>1.&#160;&#160;&#160;&#160;&#160;&#160; 特定的封闭类第一次被实例化。</p>

<p>2.&#160;&#160;&#160;&#160;&#160;&#160; 特定封闭类中任一静态成员变量被调用。</p>

<p>泛型类中的方法重载</p>

<p>方法的重载在.Net Framework中被大量应用，他要求重载具有不同的签名。在泛型类中，由于通用类型T在类编写时并不确定，所以在重载时有些注意事项，这些事项我们通过以下的例子说明：</p>

<p>public class Node&lt;T, V&gt; </p>

<p>&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public T add(T a, V b)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //第一个add</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return a;</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public T add(V a, T b)&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //第二个add</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return b;</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public int add(int a, int b)&#160;&#160;&#160; //第三个add</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return a + b;</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>

<p>}</p>

<p>上面的类很明显，如果T和V都传入int的话，三个add方法将具有同样的签名，但这个类仍然能通过编译，是否会引起调用混淆将在这个类实例化和调用add方法时判断。请看下面调用代码：</p>

<p>Node&lt;int, int&gt; node = new Node&lt;int, int&gt;();</p>

<p>&#160;&#160;&#160; object x = node.add(2, 11);</p>

<p>这个Node的实例化引起了三个add具有同样的签名，但却能调用成功，因为他优先匹配了第三个add。但如果删除了第三个add，上面的调用代码则无法编译通过，提示方法产生的混淆，因为运行时无法在第一个add和第二个add之间选择。</p>

<p>Node&lt;string, int&gt; node = new Node&lt;string, int&gt;();</p>

<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; object x = node.add(2, &quot;11&quot;);</p>

<p>&#160;&#160; 这两行调用代码可正确编译，因为传入的string和int，使三个add具有不同的签名，当然能找到唯一匹配的add方法。</p>

<p>由以上示例可知，C#的泛型是在实例的方法被调用时检查重载是否产生混淆，而不是在泛型类本身编译时检查。同时还得出一个重要原则：</p>

<p>当一般方法与泛型方法具有相同的签名时，会覆盖泛型方法。</p>

<p>泛型类的方法重写</p>

<p>方法重写（override）的主要问题是方法签名的识别规则，在这一点上他与方法重载一样，请参考泛型类的方法重载。</p>

<p>泛型的使用范围</p>

<p>本文主要是在类中讲述泛型，实际上，泛型还可以用在类方法、接口、结构（struct）、委托等上面使用，使用方法大致相同，就不再讲述。</p>

<p>小结</p>

<p>C# 泛型是开发工具库中的一个无价之宝。它们可以提高性能、类型安全和质量，减少重复性的编程任务，简化总体编程模型，而这一切都是通过优雅的、可读性强的语法完成的。尽管 C# 泛型的根基是 C++ 模板，但 C# 通过提供编译时安全和支持将泛型提高到了一个新水平。C# 利用了两阶段编译、元数据以及诸如约束和一般方法之类的创新性的概念。毫无疑问，C# 的将来版本将继续发展泛型，以便添加新的功能，并且将泛型扩展到诸如数据访问或本地化之类的其他 .NET Framework 领域。</p><img src="http://www.cnblogs.com/Lileltp/aggbug/1525053.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2009/07/16/1525053.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2009/07/16/1525053.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>vs2008中服务资源管理器中无法添加sqlserver服务器</title><link>http://www.cnblogs.com/Lileltp/archive/2009/04/29/1446554.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Wed, 29 Apr 2009 13:48:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2009/04/29/1446554.html</guid><description><![CDATA[<p>阅读: 230 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2009-04-29 21:48 <a href="http://www.cnblogs.com/Lileltp/archive/2009/04/29/1446554.html" target="_blank">原文链接</a></p><p>出现以下问题 <p>无法添加数据库 <br>未能加载文件或程序集“Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral,PublicKeyToken=89845dcd8080cc91”或它的一个依赖项。系统找不到指定的文件 <p>&nbsp; <p>可以到这里 <p><a title="http://download.microsoft.com/download/b/b/2/bb22098a-c071-415f-9269-2eb26cefb562/instructions_chs.htm" href="http://download.microsoft.com/download/b/b/2/bb22098a-c071-415f-9269-2eb26cefb562/instructions_chs.htm">http://download.microsoft.com/download/b/b/2/bb22098a-c071-415f-9269-2eb26cefb562/instructions_chs.htm</a> <p>然后下载 <p> <ul>你也可直接从这个链接下载</ul></p> <p><b>Microsoft SQL Server 2008 管理对象</b> <ul>SQL Server 管理对象 (SMO) 是一个 .NET Framework 对象模型，软件开发人员使用该模型可以创建用于管理 SQL Server 对象和服务的客户端应用程序。此对象模型将与 SQL Server 2000、SQL Server 2005 和 SQL Server 2008 协同工作。<br><b>注意：</b>Microsoft SQL Server 2008 管理对象集合需要安装 <b>Microsoft Core XML Services (MSXML) 6.0</b> 和 Microsoft SQL Server Native Client，本页中也提供了这两个程序。<br>用户：<b>客户、合作伙伴、开发人员</b> <ul><b><a href="http://go.microsoft.com/fwlink/?LinkId=123708&amp;clcid=0x804">X86 包</a></b> (SharedManagementObjects.msi) - 3225 KB<br><b><a href="http://go.microsoft.com/fwlink/?LinkId=123709&amp;clcid=0x804">X64 包</a></b> (SharedManagementObjects.msi) - 3895 KB<br><b><a href="http://go.microsoft.com/fwlink/?LinkId=123710&amp;clcid=0x804">IA64 包</a></b> (SharedManagementObjects.msi) - 5640 KB</ul> <ul></ul> <ul></ul> <ul></ul> <ul></ul> <ul></ul> <ul></ul> <ul></ul></ul><img src="http://www.cnblogs.com/Lileltp/aggbug/1446554.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2009/04/29/1446554.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2009/04/29/1446554.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>Windows2008 可用的通用蓝牙驱动程序</title><link>http://www.cnblogs.com/Lileltp/archive/2009/03/20/1417703.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Fri, 20 Mar 2009 06:44:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2009/03/20/1417703.html</guid><description><![CDATA[<p>阅读: 359 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2009-03-20 14:44 <a href="http://www.cnblogs.com/Lileltp/archive/2009/03/20/1417703.html" target="_blank">原文链接</a></p><p>为了开发就装了2008,结果发现蓝牙驱不起来了.以前也弄过2003和2008的驱动.但是那个适配器估计好些?开始用的Widcomm.结果这次弄的那个小的蓝牙适配器一安装驱动就死机.后来没法子弄了IVT.也是破解了就不能用了.可怜看我马上就要到实用的天数了我鼠标就不能用了.</p>
<p>找啊找.还真让我找到了.</p>
<p>不敢独享.发出来给和我一样的兄弟.</p>
<p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:d5d24247-8867-4701-b22f-9e2db7a2ce26" class="wlWriterEditableSmartContent">
<p><a title="win2008蓝牙驱动" href="http://files.cnblogs.com/Lileltp/bt.zip">win2008蓝牙驱动</a></p>
</div>
<img src="http://www.cnblogs.com/Lileltp/aggbug/1417703.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2009/03/20/1417703.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2009/03/20/1417703.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在ASP.NET中使用ObjectDataSource来实现数据的增删改查(目录)</title><link>http://www.cnblogs.com/Lileltp/archive/2008/09/05/ObjectDataSource.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Fri, 05 Sep 2008 08:36:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/09/05/ObjectDataSource.html</guid><description><![CDATA[<p>阅读: 363 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-09-05 16:36 <a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/ObjectDataSource.html" target="_blank">原文链接</a></p><p>前言:    <br />在学习ASP.NET2.0的时候发现在操作数据的时候微软给我们提供了几个数据源控件.     <br />然而每个控件也有各自的优缺点.比如说SqlDataSource使用起来方便. </p>  <p>可是在我们做项目中时常要将项目分层次来进行开发.于是我很少用到SqlDataSource,那么就开始关注ObjectDataSource了.    <br />但是在使用的时候发现有很多问题.到网上查找确没有一些很好的答案,问到多数的前辈大部分都是说从来不用这个东西.^_^     <br />其实按照以前的写法我也可以不用.但是出于研究的目的于是乎自己弄的试了试.那下面的内容就是在学习中遇到的问题并找到解决的答案,如果你也在学习这个ObjectDataSource那么你可以看看我解决的方式和你的方式有什么区别.有了好的可一定要告我. </p>  <p><font color="#0080ff">注:这里主要是为了探讨和ObjectDataSource配合使用.验证啊样式啊什么的不在讨论的范围之内.^_^</font></p>  <p><font color="#0080ff"></font></p>  <ul>   <li><a href="http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html">在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据</a>      <br />      <br />这部分内容使用ObjectDataSource和GridView配合实现数据基本的显示和排序      <br /></li>    <li><a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html">在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据(2)</a>      <br />      <br />在上一次基础上实现了通过参数显示和分页      <br /></li>    <li><a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html">在ASP.NET中使用ObjectDataSource数据控件和GridView操作数据</a>      <br />      <br />使用ObjectDataSource来实现我们的数据的删除和修改      <br /></li>    <li><a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html">在ASP.NET中使用ObjectDataSource数据控件实现插入新记录</a>      <br />      <br />实现使用ObjectDataSource和DetailsView或FormView插入新的记录</li> </ul>   <img src="http://www.cnblogs.com/Lileltp/aggbug/1285240.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/ObjectDataSource.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/ObjectDataSource.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在ASP.NET中使用ObjectDataSource数据控件实现插入新记录</title><link>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Fri, 05 Sep 2008 08:26:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html</guid><description><![CDATA[<p>阅读: 164 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-09-05 16:26 <a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html" target="_blank">原文链接</a></p><p>^_^终于我们把GridView和ObjectDataSource配合弄好了.想怎么删除就删除,想怎么修改就怎么修改.结果当我删除完以后.哦哦哦.没录入啊.这可不行.总不能到数据库那里录入吧.恩.这样吧配合ObjectDataSource实现录入一定的弄出来.</p>  <p>先做个界面</p>  <p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="336" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_thumb.png" width="410" border="0" /></a> </p>  <p>哦.那添加的那个界面是不是需要像以前那样弄个表格呢?那样还有什么意思啊.</p>  <p>这里我用的是</p>  <p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="48" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_thumb_1.png" width="149" border="0" /></a> </p>  <p>这里的第一个DetailsView</p>  <p>不过默认的时候是读取的样子.那怎么弄呢.</p>  <p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_6.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="33" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSource_E712/image_thumb_2.png" width="379" border="0" /></a> </p>  <p>设置这个属性到Insert</p>  <p>这样就和我上面一样了.</p>  <p>下一步你就可以把你的DetailsView绑定到和GridView相关联的ObjectDataSource上了.因为我们前面已经搞定了Insert的方法所以这里就直接可以使用了.</p>  <p><a title="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html" href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html">http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html</a></p>  <p>同理你也可以使用FormView来实现我们这里的录入内容</p><img src="http://www.cnblogs.com/Lileltp/aggbug/1285232.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285232.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在ASP.NET中使用ObjectDataSource数据控件和GridView操作数据</title><link>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Fri, 05 Sep 2008 07:26:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html</guid><description><![CDATA[<p>阅读: 388 评论: 1 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-09-05 15:26 <a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html" target="_blank">原文链接</a></p><p>通过前两次的内容我们已经实现了带有分页和排序的显示数据,那么我们如何用ObjectDataSource来帮助我们实现删改</p>  <p>还是老办法我们先实现DAL层和BLL层当中的操作数据的方法</p>  <pre style="background-color: #f4f4f4">        [DataObjectMethod(DataObjectMethodType.Insert)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> InserUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.InsertUserInfo(info);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> UpdateUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.UpdateUserInfo(info);
        }

        [DataObjectMethod(DataObjectMethodType.Delete)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> DeleteUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.DeleteUserInfo(info);
        }</pre>

<p>&#160;</p>

<p>这里我们可以发现我这里传递的都是UserInfo对象了.至于好处嘛,我认为你在赋值的时候通过属性对其处理安全性更好一些.反正我总觉得比传一大堆的变量过来要好.所以这里采用这个方式.</p>

<p>如果你要采用我这种方式那么就需要注意你的ObjectDataSource中的一个属性是否正确设置了</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_2.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="29" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb.png" width="291" border="0" /></a> </p>

<p>这里我设置为我查询出的对象UserInfo</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_4.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="183" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_1.png" width="408" border="0" /></a> </p>

<p>这样你就可以来实现删除和修改了.有些人就问呀!我没有像以前那样设置传递的参数啊.^_^</p>

<p>这里当你设置了ObjectDataSource的DataObjectTypeName,当你执行相关操作的时候ObjectDataSource就会自动生成一个你设置的对象并且将行内的值一一对应的传入到你的这个对象.然后直接将这个对象传入到你的BLL中的方法.<font color="#ff0000">但是要注意,这里还是有很多陷阱的</font></p>

<p><font color="#ff0000"></font></p>

<p>第一个陷阱 由数据冲突引起的问题<a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_6.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="27" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_2.png" width="271" border="0" /></a> 

  <br />在ObjectDataSource中有个属性&#8593;</p>

<p>这里属性来设置如何处理是否新旧值一起处理</p>

<p>MSDN上的描述为:获取或设置一个值，该值确定是仅将新值传递给 Update 方法，还是将旧值和新值都传递给 Update 方法。</p>

<p>当这里使用默认的<font color="#0000ff">OverwriteChanges</font>的时候传递的值内容为你更改后值.这里传递是我们修改后的对象值.所以默认状态下你的更新是没有问题的.</p>

<p>但如果你要处理新旧值的时候就需要设置到<font color="#0000ff">CompareAllValues.</font><font color="#000000">但是这时你再更新数据的时候就会报错了.</font></p>

<p><font color="#000000">为什么会这样呢?原来当你设置为<font color="#0000ff">CompareAllValues</font>的时候他需要给你BLL层传递过两个对象,一个是原来的UserInfo一个是你修改后的Userinfo.</font></p>

<p><font color="#000000">所以你的方法需要改成这样
    <br /></font>

  <p></p>
  <font color="#000000"></font></p>

<pre style="background-color: #f4f4f4">        [DataObjectMethod(DataObjectMethodType.Update)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> UpdateUserInfo(UserInfo info,UserInfo original_info)
        {
            ......
        }</pre>
这里发现我们的更新方法多了后面的一个参数叫original_info,这样才能将我们的修改后的内容正确更新回数据库,而且这里的original_这个前缀可以通过修改<a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_8.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="22" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_3.png" width="290" border="0" /></a> 

<p><font color="#000000">来实现.</font></p>

<p>陷阱二,键字段的问题.</p>

<p>那当我们ConflicDetection使用默认的<font color="#0000ff">OverwriteChanges</font>值的时候我们进行删除操作.发现没有删除了我们想要操作的那条记录.然后通过监视可以发现传递到BLL中的UserInfo对象虽不为空.但是里面属性的值都为默认值</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_10.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="406" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_4.png" width="419" border="0" /></a> </p>

<p>那为什么会出现这个问题呢?我认为是,删除操作并没有修改我GridView中的记录所以在ConflicDetection使用默认的<font color="#0000ff">OverwriteChanges</font>值的时候传递过的对象里要是有值只能是修改后的值.所以这里你要通过id来删除则只能删除记录为0的了.^_^</p>

<p>所以通常来说删除不了你想要的内容,但是不出错.</p>

<p>那怎么办呢?这里因为我们使用的是集合所以在编写GridView的时候少设置了一个属性,那就是<a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_12.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="28" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_5.png" width="305" border="0" /></a> </p>

<p>这里我们添加上键字段id.再来看看效果</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_14.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="418" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_9467/image_thumb_6.png" width="420" border="0" /></a> </p>

<p>这次发现,虽然这里没有吧UserInfo对象完整的传递过来.但是我们想要的id值过来了.^_^</p>

<p><font color="#000000"></font></p><img src="http://www.cnblogs.com/Lileltp/aggbug/1285180.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1285180.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据(2)</title><link>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Thu, 04 Sep 2008 16:05:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html</guid><description><![CDATA[<p>阅读: 282 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-09-05 00:05 <a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html" target="_blank">原文链接</a></p><p>接上回书说,我们实现了基本的显示和排序.那么今天就来做做查询和分页.</p>  <p>首先先做通过传递普通参数的形式来实现条件查询的.这里仅仅做个演示.</p>  <p>我们要通条件查询那就需要修改我们原来的查询方法了.</p>  <pre style="background-color: #ccc">        [DataObjectMethod(DataObjectMethodType.Select)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> List&lt;UserInfo&gt; GetUserInfoList(<span style="color: #0000ff">string</span> name, <span style="color: #0000ff">string</span> sort)
        {
           ........
        }</pre>

<p>我们这里加了一个参数用来传入要查询的用户名称.</p>

<p>但是这里一定要注意.当你修改了后面的方法后<font color="#ff0000">一定要做一件事情.</font></p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="80" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_thumb.png" width="163" border="0" /></a> </p>

<p>那就是<font color="#ff0000">配置数据源</font></p>

<p>因为我们修改后面的方法参数所以这里也变化了如果不重新配置数据源就会报一个错误那就是</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="226" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_thumb_1.png" width="584" border="0" /></a> </p>

<p>当你重新配置数据源的时候就可以给你的参数设置值的来源了</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="185" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView2_EBB5/image_thumb_2.png" width="631" border="0" /></a> </p>

<p>这里我给name参数设置了值的来源为控件类型.控件名为txt_name,这样你就可以通过传递的值来改变你返回集合的内容了.而且这里因为我们指定数据来源是txt_name所以当你点击查询按钮的时候,他会自动重新绑定GridView控件.也就是你不必再执行GridView的DataBind方法了</p>

<p>上面已经实现了一点点效果了那最后就实现我们这次要最终想要的结果吧.</p>

<p>在传递值的时候会发现如果传递多个查询条件的时候参数还是比较多的.而且我们本来是有那个UserInfo类的,那我们干脆把要查询的条件内容放到一个对象里传过来好了,那样还能通过他的属性Set方法来验证一下.</p>

<pre style="background-color: #ccc"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> List&lt;UserInfo&gt; GetUserInfoList(UserInfo info,<span style="color: #0000ff">int</span> start,<span style="color: #0000ff">int</span> max, <span style="color: #0000ff">string</span> sort)
{
	......
}</pre>

<p>那么我们捎带的就把分页也做了吧.</p>

<p>根据我们的要求就把原来的方法改写成&#8593;这样的了.传递了一个对象和分页的两个参数 </p>

<p>在这里我们可以和上次说到的排序那样来在ObjectDataSource中设置这两个参数他们分别是</p>

<p>StartRowParameterName和MaximumRowsParamterName</p>

<p>但是我这里使用通过在ObjectDataSource的Selecting事件中给这个赋值,这样就直接可以使用第三方的分页控件了</p>

<pre style="background-color: #ccc">        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> ObjectDataSource1_Selecting(<span style="color: #0000ff">object</span> sender, ObjectDataSourceSelectingEventArgs e)
        {
            Models.UserInfo info = <span style="color: #0000ff">new</span> Models.UserInfo();
            info.uname = txt_name.Text;
            e.InputParameters[&quot;<span style="color: #8b0000">info</span>&quot;] = info;

            e.InputParameters[&quot;<span style="color: #8b0000">start</span>&quot;]=传入的值;
            e.InputParameters[&quot;<span style="color: #8b0000">max</span>&quot;]=传入的值;
        }</pre>

<p>这样我们就可以将你自己赋值的info对象和从分页控件得来的start和max值传入到BLL中的Select方法中了.</p>

<p>这里讲述了如何通过事件给已订好的方法动态的传递你的值.</p>

<p><font color="#ff0000">这里需要注意:因为现在的参数是后期才赋值的所以你必须在你的查询按钮中添加一句话</font></p>

<pre style="background-color: #ccc">        <span style="color: #0000ff">protected</span> <span style="color: #0000ff">void</span> btn_query_Click(<span style="color: #0000ff">object</span> sender, EventArgs e)
        {
            GridView1.DataBind();//这里必须重新绑定一下GridView
        }</pre><img src="http://www.cnblogs.com/Lileltp/aggbug/1284764.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/05/1284764.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在ASP.NET中使用ObjectDataSource数据控件和GridView显示数据</title><link>http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Thu, 04 Sep 2008 07:47:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html</guid><description><![CDATA[<p>阅读: 298 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-09-04 15:47 <a href="http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html" target="_blank">原文链接</a></p><p>前言:    <br />在学习ASP.NET2.0的时候发现在操作数据的时候微软给我们提供了几个数据源控件.     <br />然而每个控件也有各自的优缺点.比如说SqlDataSource使用起来方便. </p>  <p>可是在我们做项目中时常要将项目分层次来进行开发.于是我很少用到SqlDataSource,那么就开始关注ObjectDataSource了.    <br />但是在使用的时候发现有很多问题.到网上查找确没有一些很好的答案,问到多数的前辈大部分都是说从来不用这个东西.^_^     <br />其实按照以前的写法我也可以不用.但是出于研究的目的于是乎自己弄的试了试.那下面的内容就是在学习中遇到的问题并找到解决的答案,如果你也在学习这个ObjectDataSource那么你可以看看我解决的方式和你的方式有什么区别.有了好的可一定要告我. </p>  <p>&#160;</p>  <p>第一部分 使用ObjectDataSource实现显示和排序</p>  <p>在这里我使用的是泛型集合,所以我做查询的时候返回的不是DataSet,那么就先编写DAL中的返回泛型结合的方法了</p>  <pre style="background-color: #ccc">        #region 显示
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> SortableList&lt;UserInfo&gt; GetUserInfoList()
        {
            SortableList&lt;UserInfo&gt; list = <span style="color: #0000ff">new</span> SortableList&lt;UserInfo&gt;();
            <span style="color: #0000ff">using</span> (SqlDataReader dr = Database.ExecuteReader(Database.ConnectionString, CommandType.Text, &quot;<span style="color: #8b0000">select * from userinfo</span>&quot;))
            {
                <span style="color: #0000ff">while</span> (dr.Read())
                {
                    UserInfo info = <span style="color: #0000ff">new</span> UserInfo();
                    info.id = Convert.ToInt16(dr[&quot;<span style="color: #8b0000">id</span>&quot;]);
                    info.uname = dr[&quot;<span style="color: #8b0000">uname</span>&quot;].ToString();
                    info.age = Convert.ToInt16(dr[&quot;<span style="color: #8b0000">age</span>&quot;]);
                    info.sex = (<span style="color: #0000ff">int</span>)dr[&quot;<span style="color: #8b0000">sex</span>&quot;];
                    list.Add(info);
                }
            }
            <span style="color: #0000ff">return</span> list;
        }
        #endregion</pre>

<p>通过上面的代码就实现了返回一个UserInfo的集合 </p>

<p>为了使ObjectDataSource在使用的时候能直接找到用于处理的类和方法就需要给类和方法加上相关的属性描述</p>

<pre style="background-color: #ccc"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Collections.Generic;
<span style="color: #0000ff">using</span> System.Text;
<span style="color: #0000ff">using</span> System.ComponentModel;<span style="color: #008000">//首先这里要引用相关的命名空间</span> 
<span style="color: #0000ff">using</span> Models;

<span style="color: #0000ff">namespace</span> BLL
{
    [DataObject()]<span style="color: #008000">//这里给类加上描述</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> UserInfoBLL
    {
        [DataObjectMethod(DataObjectMethodType.Select)]<span style="color: #008000">//这里告诉ObjectDataSource是用来查询的方法</span> 
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> List&lt;UserInfo&gt; GetUserInfoList(<span style="color: #0000ff">string</span> sort)
        {
            SortableList&lt;UserInfo&gt; list = DAL.UserInfoDAL.GetUserInfoList();
            <span style="color: #0000ff">if</span> (!sort.Equals(&quot;<span style="color: #8b0000"></span>&quot;))
            {
                <span style="color: #0000ff">bool</span> flag = <span style="color: #0000ff">true</span>;
                <span style="color: #0000ff">if</span> (sort.IndexOf(&quot;<span style="color: #8b0000">DESC</span>&quot;)!=-1)
                {
                    flag = <span style="color: #0000ff">false</span>;
                }
                list.Sort(sort.Replace(&quot;<span style="color: #8b0000"> DESC</span>&quot;,&quot;<span style="color: #8b0000"></span>&quot;), flag);
            }
            
            <span style="color: #0000ff">return</span> list;
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> InserUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.InsertUserInfo(info);
        }

        [DataObjectMethod(DataObjectMethodType.Update)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> UpdateUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.UpdateUserInfo(info);
        }

        [DataObjectMethod(DataObjectMethodType.Delete)]
        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> DeleteUserInfo(UserInfo info)
        {
            DAL.UserInfoDAL.DeleteUserInfo(info);
        }

        <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> DeleteMulutiUserInfo(<span style="color: #0000ff">string</span> userlist)
        {
            DAL.UserInfoDAL.DeleteMulutiUserInfo(userlist);
        }
    }
}</pre>

<p>然后就可以在你的ASP.NET页面中添加GridView和ObjectDataSource控件了.剩下就是配置你的数据源</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_4.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="395" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_thumb_1.png" width="536" border="0" /></a> </p>

<p>这里面选着你的Select方法</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_6.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="257" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_thumb_2.png" width="533" border="0" /></a> </p>

<p>对于下一步要求的输入sort参数这里不做设置就按照默认的方式</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_8.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="154" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_thumb_3.png" width="535" border="0" /></a> </p>

<p>然后你就可以高兴的运行起来看一下了.showshow我的效果</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_10.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="204" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_thumb_4.png" width="406" border="0" /></a> </p>

<p>那如果没有问题接下来做我们的排序吧.因为我们在编写后台代码的时候已经添加了一个sort参数,所以这里就简单了.</p>

<p>首先设置ObjectDataSource的一个属性<font color="#ff0000">SortParamterName </font><font color="#000000">这里我们设置为刚才BLL中的那个传入的那个参数sort</font></p>

<p>然后就可以启用排序内容了</p>

<p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_12.png"><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="363" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/ASP.NETObjectDataSourceGridView_D873/image_thumb_5.png" width="243" border="0" /></a> </p>

<p>现在就能实现排序了.当然我这里是重新写了个sortlist的泛型集合.对于普通的应用你可以通过直接变化你的SQL语句来实现这个排序的功能.应为当你第一次点击某一列的时候他会传入那个列名,比如ID,而第二次点击则会传入ID DESC </p><img src="http://www.cnblogs.com/Lileltp/aggbug/1284082.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/09/04/1284082.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>在sqlserver2005中部署C#编写的自定义函数</title><link>http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058582.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Wed, 30 Jan 2008 04:56:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058582.html</guid><description><![CDATA[<p>阅读: 263 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-01-30 12:56 <a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058582.html" target="_blank">原文链接</a></p><p>第一步先要创建一个C#语言的SQLSERVER项目</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/sqlserver2005C_F5E6/image_2.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="259" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/sqlserver2005C_F5E6/image_thumb.png" width="404" border="0"></a> </p> <p>添加一个新的项,这里先添加一个"用户自定义函数"</p> <p><a href="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/sqlserver2005C_F5E6/image_6.png"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="232" alt="image" src="http://www.cnblogs.com/images/cnblogs_com/Lileltp/WindowsLiveWriter/sqlserver2005C_F5E6/image_thumb_2.png" width="404" border="0"></a> </p> <p>&nbsp;</p> <p>然后来看个最简单的代码.^_^.</p> <div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 98.37%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 228px; background-color: #f4f4f4"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">using</span> System;
<span style="color: #0000ff">using</span> System.Data;
<span style="color: #0000ff">using</span> System.Data.SqlClient;
<span style="color: #0000ff">using</span> System.Data.SqlTypes;
<span style="color: #0000ff">using</span> Microsoft.SqlServer.Server;

<span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> UserDefinedFunctions
{
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// 定义一个sql的函数</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name="element"&gt;需要切分的字符串&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name="index"&gt;想要得到字符串的位置&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;returns&gt;结果&lt;/returns&gt;</span>
    [Microsoft.SqlServer.Server.SqlFunction]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> SqlString MySplit(<span style="color: #0000ff">string</span> element,<span style="color: #0000ff">int</span> index)
    {
        <span style="color: #0000ff">return</span> element.Split(<span style="color: #006080">','</span>)[index];
    }
};

</pre></div>
<p>&nbsp;</p>
<p>ok,当你写好代码了就该生成部署了.通过菜单 生成→部署</p>
<p>部署好以后就可以在查询分析器中试一下了</p>
<p>不过需要设置一下SQL2005,打开CLR支持</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">EXEC</span> sp_configure <span style="color: #006080">'show advanced options'</span>, 1 
<span style="color: #0000ff">GO</span> 
<span style="color: #0000ff">RECONFIGURE</span> 
<span style="color: #0000ff">GO</span> 
 
<span style="color: #0000ff">EXEC</span> sp_configure <span style="color: #006080">'clr enabled'</span>, 1 
<span style="color: #0000ff">GO</span> 
<span style="color: #0000ff">RECONFIGURE</span> 
<span style="color: #0000ff">GO</span> </pre></div>
<p>然后就可以执行了</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">SELECT</span> dbo.MySplit(<span style="color: #006080">'你好,我爱你,呵呵,爽啊'</span>,2)</pre></div>结果当然就是"呵呵"<img src="http://www.cnblogs.com/Lileltp/aggbug/1058582.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058582.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058582.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item><item><title>Javascript 中 &amp;quot;=&amp;quot; ,&amp;quot;==&amp;quot;,&amp;quot;===&amp;quot;的区别与关系</title><link>http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058578.html</link><dc:creator>阿呆乐</dc:creator><author>阿呆乐</author><pubDate>Wed, 30 Jan 2008 04:51:00 GMT</pubDate><guid>http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058578.html</guid><description><![CDATA[<p>阅读: 86 评论: 0 作者: <a href="http://www.cnblogs.com/Lileltp/" target="_blank">阿呆乐</a> 发表于 2008-01-30 12:51 <a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058578.html" target="_blank">原文链接</a></p><div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"> <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;!</span><span style="color: #800000">DOCTYPE</span> <span style="color: #ff0000">html</span> <span style="color: #ff0000">PUBLIC</span> <span style="color: #0000ff">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="color: #0000ff">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">html</span> <span style="color: #ff0000">xmlns</span><span style="color: #0000ff">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">meta</span> <span style="color: #ff0000">http-equiv</span><span style="color: #0000ff">="Content-Type"</span> <span style="color: #ff0000">content</span><span style="color: #0000ff">="text/html; charset=utf-8"</span> <span style="color: #0000ff">/&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span>无标题 1<span style="color: #0000ff">&lt;/</span><span style="color: #800000">title</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">script</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">="text/javascript"</span><span style="color: #0000ff">&gt;</span><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   1:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   2:</span>     <span style="color: #0000ff">function</span> alertInfo()</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   3:</span>     {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   4:</span>         <span style="color: #0000ff">var</span> m=<span style="color: #006080">"5"</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   5:</span>         <span style="color: #0000ff">var</span> n=5;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   6:</span>         <span style="color: #0000ff">var</span> x=5.0;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   7:</span>         <span style="color: #0000ff">var</span> o=<span style="color: #0000ff">null</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">   8:</span>         <span style="color: #0000ff">var</span> oo=<span style="color: #0000ff">null</span>;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">   9:</span>         <span style="color: #0000ff">if</span>(m==n)</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  10:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  11:</span>             alert(<span style="color: #006080">'使用 == m 和 n 相等'</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  12:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  13:</span>         </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  14:</span>         <span style="color: #0000ff">if</span>(m===n)<span style="color: #008000">//一个是字符串一个是数字</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  15:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  16:</span>             alert(<span style="color: #006080">'使用 === m 和 n 相等'</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  17:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  18:</span>         </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  19:</span>         <span style="color: #0000ff">if</span>(n===x)<span style="color: #008000">//这里两个都是数字的类型</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  20:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  21:</span>             alert(<span style="color: #006080">'使用 === n 和 x 相等'</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  22:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  23:</span>         </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  24:</span>         <span style="color: #0000ff">if</span>(o===oo)<span style="color: #008000">//最后两个内容都为null        </span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  25:</span>         {</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  26:</span>             alert(<span style="color: #006080">'使用 === o 和 oo 相等'</span>);</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  27:</span>&nbsp; </pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #606060">  28:</span>         }</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #606060">  29:</span>     }</pre><span style="color: #0000ff">&lt;/</span><span style="color: #800000">script</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">head</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none"><span style="color: #0000ff">&lt;</span><span style="color: #800000">input</span> <span style="color: #ff0000">name</span><span style="color: #0000ff">="Button1"</span> <span style="color: #ff0000">type</span><span style="color: #0000ff">="button"</span> <span style="color: #ff0000">value</span><span style="color: #0000ff">="按钮"</span> <span style="color: #ff0000">onclick</span><span style="color: #0000ff">="alertInfo()"</span> <span style="color: #0000ff">/&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">body</span><span style="color: #0000ff">&gt;</span></pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: white; border-bottom-style: none">&nbsp;</pre><pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">&lt;/</span><span style="color: #800000">html</span><span style="color: #0000ff">&gt;</span></pre></div></div>
<p>从上面就可以看出来在javascript中 使用"="是赋值的意思.这个都可以理解.</p>
<p>而使用"==" 和"===" 则有一定的区别了.</p>
<p>在javascript中 "=="相当于C#中的equals 也就是这个只是比较内容是否相等.所以 var m="5" 和 var n=5 最后的结果是相等的.</p>
<p>而"===" 这个不但要比较内容是否相等也要比较类型是否一样.所以上面的那个值并没有打印出来.</p>
<p>但是上面的前提是一个是字符串类型一个是数字的.</p>
<p>如果两个都是数字.但是类型不一样."==="也会认为是相同的结果. 例如 var n=5.00 ; var x=5; "===" 会认为这两个值是相同的.</p><img src="http://www.cnblogs.com/Lileltp/aggbug/1058578.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058578.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/Lileltp/archive/2008/01/30/1058578.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56851/" target="_blank">苹果发布 iPhone/iPad SDK 3.2 beta2 开发包</a><span style="color:gray">(2010-02-10 15:37)</span><br/>· <a href="http://news.cnblogs.com/n/56850/" target="_blank">“谷姐”：披着“谷歌”羊皮的悲哀？</a><span style="color:gray">(2010-02-10 15:32)</span><br/>· <a href="http://news.cnblogs.com/n/56849/" target="_blank">2010，奇虎的本命年</a><span style="color:gray">(2010-02-10 15:26)</span><br/>· <a href="http://news.cnblogs.com/n/56847/" target="_blank">微软赢得Windows XP WGA诉讼</a><span style="color:gray">(2010-02-10 15:23)</span><br/>· <a href="http://news.cnblogs.com/n/56846/" target="_blank">移动版 Google Buzz 已经上线，Google 在各处强推</a><span style="color:gray">(2010-02-10 15:18)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/news/tag/Buzz/" target="_blank">Google Buzz相关新闻</a><br/></p><p>网站导航：<a href="http://www.cnblogs.com" target="_blank">博客园首页</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/" target="_blank">个人主页</a>&nbsp;&nbsp;<a href="http://news.cnblogs.com" target="_blank">新闻</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/ing/" target="_blank">闪存</a>&nbsp;&nbsp;<a href="http://home.cnblogs.com/group/" target="_blank">小组</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com/q/" target="_blank">博问</a>&nbsp;&nbsp;<a href="http://space.cnblogs.com" target="_blank">社区</a>&nbsp;&nbsp;<a href="http://kb.cnblogs.com" target="_blank">知识库</a></p>]]></description></item></channel></rss>