﻿<?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>博客园-David Qian</title><link>http://www.cnblogs.com/David-Qian/</link><description>If there's a problem, just resolve it yourself</description><language>zh-cn</language><lastBuildDate>Wed, 10 Feb 2010 06:48:51 GMT</lastBuildDate><pubDate>Wed, 10 Feb 2010 06:48:51 GMT</pubDate><ttl>60</ttl><item><title>正则表达式学习资源</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/18/1393337.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 18 Feb 2009 09:09:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/18/1393337.html</guid><description><![CDATA[<p>阅读: 868 评论: 2 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-18 17:09 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1393337.html" target="_blank">原文链接</a></p><p>这两天在琢磨着正则表达式，看到了一些比较好的资源，贴出来和大家分享：</p>
<p>正则表达式30分钟入门教程(中文，写的非常易懂，推荐一个)：<a href="http://www.cnblogs.com/netshuai/archive/2007/09/20/900032.html">http://www.cnblogs.com/netshuai/archive/2007/09/20/900032.html</a></p>
<p>微软官方教程(英文)：<a href="http://msdn.microsoft.com/en-us/library/28hw3sce.aspx">http://msdn.microsoft.com/en-us/library/28hw3sce.aspx</a></p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1393337.html?type=1" width="1" height="1" alt=""/><p>评论: 2　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1393337.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1393337.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>ApplicationName 得到的启示</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/18/1392569.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 18 Feb 2009 02:07:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/18/1392569.html</guid><description><![CDATA[<p>阅读: 1133 评论: 1 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-18 10:07 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1392569.html" target="_blank">原文链接</a></p><p>不知道大家有没有遇到过这样的情况，在测试环境中，ASP.NET程序一切运行正常，可一旦部署到远程IIS server上时，membership验证就出现问题了，Login控件提示&#8220;登录失败，请重试&#8221;。如果你遇到过这种情况，请看如下解释。</p>
<p>这大都是由于ApplicationName引起的。我们在web.config中配置membership，role，profile等信息时，正常都会添加上ApplicationName='/'或ApplicationName='specificName'。如果你没有配置ApplicationName，那么这个问题就出现了。</p>
<p>简单的说，membership验证时是需要知道application的名字的。如果你配置了，那么一切都OK。如果你没配置，它默认会添加上虚拟目录的名字。这样就有问题了，因为我们在远程IIS中很可能使用了不同名字的虚拟目录，这就导致了原来的用户无法得到验证。</p>
<p>如果你不信的话，可以在自己的机器上修改membership的ApplicationName配置，然后你再试试原来的用户能否通过验证，答案是：不能。</p>
<p>ApplicationName的配置可以是一个特定的name，如MyApp。也可以是一个斜杠'/'，它将使用ASP.NET 2.0默认配置。ApplicationName是存储在membership数据库的aspnet_Applications的表中的，大家可以check下。同时，每个用户都会对应一个applicationID(check aspnet_Users表)，这就是为什么改了ApplicationName后，原先的用户将无法验证的原因了。</p>
<p>还是老话，问题虽小，希望大家能理解其中的原理，对今后有所帮助！同时，我也希望大家能够说说自己的理解和感受，并把自己的一些经验分享出来，让所有人都能得到提升！</p>
<p>Have a nice day!</p>
<p>&nbsp;</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1392569.html?type=1" width="1" height="1" alt=""/><p>评论: 1　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1392569.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/18/1392569.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>LINQ-SQL 中调用存储过程</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/13/1389252.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Fri, 13 Feb 2009 02:05:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/13/1389252.html</guid><description><![CDATA[<p>阅读: 1949 评论: 8 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-13 10:05 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/13/1389252.html" target="_blank">原文链接</a></p><p>这个问题被customer问了多次了，我想问题虽小，但可能对大家有帮助，就顺便写下来和大家分享。</p>
<p>问题是这样的，在LINQ-SQL中调用一个存储过程时，很多customer不知道怎么去接受返回的结果集。所以很多人就这样做了，当然，看起来是能理解的：</p>
<div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">SampleDataContext&nbsp;test&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SampleDataContext();<br />
IEnumerable</span><span style="color: #000000">&lt;</span><span style="color: #000000">tab1</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;retVal&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;test.sp();&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;error&nbsp;here!</span></div>
<p>但是在编译时就会出错，报一个类型转换的错误。其实在LINQ-SQL中调用SP时，LINQ-SQL会自动为返回的结果集生成一个类型，类型的名字是由 SP名+"Result" 组成。如SP名是sp，那么生成的类型就是 spResult。而调用SP时所返回的结果集就是 ISingleResult&lt;spResult&gt;。至于为什么会报类型转换错误呢，很简单，ISingleResult&lt;T&gt;和IEnumerable&lt;T&gt;不能互转。</p>
<p>现在大家应该知道该怎么做了吧？Try下如下代码：</p>
<div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">SampleDataContext&nbsp;test&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SampleDataContext();<br />
ISinlgeResult</span><span style="color: #000000">&lt;</span><span style="color: #000000">spResult</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;retValue&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;test.sp();<br />
</span><span style="color: #0000ff">foreach</span><span style="color: #000000">(spResult&nbsp;value&nbsp;</span><span style="color: #0000ff">in</span><span style="color: #000000">&nbsp;retValue)<br />
{<br />
&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;field&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;value.field;<br />
&nbsp;&nbsp;&nbsp;<img alt="" src="http://www.cnblogs.com/Images/dot.gif" /><br />
}</span></div>
<p>知道了怎么做还远远不够，建议大家去看看LINQ-SQL自动生成的代码。如果有这样的习惯，相信大家很容易就能自己解决问题了。不过LINQ-SQL还有个小bug，如SingleResult所暗示的一样，它还不能为我们生成MultipleResults，如SP中含有两条Select语句时。如果大家遇到这种情况，请给我留言，我会把解决的方法贴出来，现在还是开始工作了:)</p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1389252.html?type=1" width="1" height="1" alt=""/><p>评论: 8　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/13/1389252.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/13/1389252.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>为什么 SqlCommand.ExecuteNonQuery() 方法返回 -1？</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/12/1388488.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Thu, 12 Feb 2009 02:17:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/12/1388488.html</guid><description><![CDATA[<p>阅读: 2452 评论: 7 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-12 10:17 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/12/1388488.html" target="_blank">原文链接</a></p><p>不知道大家在使用ExecuteNonQuery方法的时候有没有碰到过返回-1的情况。ExecuteNonQuery方法返回增删改时，受影响的行数。那怎么会返回-1呢？查了一些资料后终于得知返回-1的原因。</p>
<p>在进行增删改时，数据库能为我们统计受影响行数的前提条件是，关闭NOCOUNT，即 Set nocount off。默认情况下，它是关闭的，即我们是可以得到受影响的行数的。你可以测试如下(加与不加set nocount on是有区别的)：</p>
<div class="cnblogs_code"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">SqlCommand&nbsp;cmd&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">new</span><span style="color: #000000">&nbsp;SqlCommand(</span><span style="color: #800000">"</span><span style="color: #800000">set&nbsp;nocount&nbsp;on;&nbsp;insert&nbsp;into&nbsp;test&nbsp;values&nbsp;('test')</span><span style="color: #800000">"</span><span style="color: #000000">,&nbsp;con);<br />
</span><span style="color: #0000ff">int</span><span style="color: #000000">&nbsp;rows&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;cmd.ExecuteNonQuery();</span></div>
<p>有的人就说了，我仅仅是调用一个简单的存储过程，怎么还是返回-1呢？这个是由于Visual Studio引起的。</p>
<p>我们在Visual Studio中写了一个存储过程时，它会被默认加上set nocount on。这样就导致了调用存储过程时始终得不到影响的行数，而返回-1。不过我在Visual Studio 2008 Team Suit中测试了下，这个问题不存在了。可能以前的版本有这样的问题吧(未测试)，碰到这种情况就多留意些。</p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1388488.html?type=1" width="1" height="1" alt=""/><p>评论: 7　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/12/1388488.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/12/1388488.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>【LINQ-SQL Debug】 一个实用工具</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388450.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 11 Feb 2009 09:12:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388450.html</guid><description><![CDATA[<p>阅读: 256 评论: 0 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-11 17:12 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388450.html" target="_blank">原文链接</a></p><p>LINQ-SQL开发时比较实用的一个tool，LINQ-SQL Debug Visualizer。它可以帮助我们调试LINQ query所生成的扩展方法，以及转换的SQL脚本等，比Visual Studio自带的Debug工具要强大一些，能反馈出更多的信息。</p>
<p>废话不多说，下载，安装，教程都在ScottGu的这篇文章中：</p>
<p><a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx">http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx</a></p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1388450.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388450.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388450.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>个人简历</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388420.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 11 Feb 2009 09:00:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388420.html</guid><description><![CDATA[<p>阅读: 17 评论: 0 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-11 17:00 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388420.html" target="_blank">原文链接</a></p>该文被密码保护。<img src="http://www.cnblogs.com/David-Qian/aggbug/1388420.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388420.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/11/1388420.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>LINQ query不支持CopyToDataTable</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/05/1383255.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Thu, 05 Feb 2009 04:31:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/05/1383255.html</guid><description><![CDATA[<p>阅读: 892 评论: 6 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-05 12:31 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/05/1383255.html" target="_blank">原文链接</a></p><p>今天有个customer说，在LINQ query出来的结果集上使用CopyToDataTable方法时，得到的DataTable是有问题的。刚开始也觉得奇怪呢，后来在网上搜索了一下，发现这确实是个问题。</p>
<p>CopyToDataTable&lt;T&gt;方法在目前来说，只能使用在T是DataRow的情形(在以后版本中应该会加强这个功能)。在我们普通的LINQ query中不能使用。如果你想将LINQ query后的结果集转换成一个DataTable，你可以自己写一个IQueryable&lt;T&gt;或IEnumerable&lt;T&gt;的扩展方法。这里有一个很好的例子：</p>
<p><a href="http://blogs.msdn.com/aconrad/archive/2007/09/07/science-project.aspx">http://blogs.msdn.com/aconrad/archive/2007/09/07/science-project.aspx</a></p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1383255.html?type=1" width="1" height="1" alt=""/><p>评论: 6　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/05/1383255.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/05/1383255.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>Data Access FAQ (二)</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383246.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 04 Feb 2009 01:48:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383246.html</guid><description><![CDATA[<p>阅读: 1540 评论: 10 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-04 09:48 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383246.html" target="_blank">原文链接</a></p><p>这里是ASP.NET Data Access FAQ的第二部分：<br />
&nbsp;</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 14pt; color: #548dd4; line-height: 115%">LINQ</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How can I implement a transaction in LINQ?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> You can use TransactionScope class in LINQ to implement a transaction. It&#8217;s a new function in .NET Framework 2.0 to provide an implicit way to implement a transaction. You can use it in LINQ as shown below:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">using</span><span style="font-size: 9pt; font-family: 新宋体"> (<span style="color: #2b91af">TransactionScope</span> scope = <span style="color: blue">new</span> <span style="color: #2b91af">TransactionScope</span>())</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">{</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">try</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 'Times New Roman','serif'">&#8230;&#8230;&#8230;</span><span style="font-size: 9pt; font-family: 新宋体">.&nbsp;&nbsp;&nbsp; </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.SubmitChanges();</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 9pt; font-family: 'Times New Roman','serif'">&#8230;&#8230;&#8230;</span><span style="font-size: 9pt; font-family: 新宋体">.&nbsp;&nbsp;&nbsp; </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ctx.SubmitChanges();</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">catch</span> (<span style="color: #2b91af">Exception</span> ex)</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(<span style="color: #a31515">"Error happens, Transaction class will automaticlly roll back!"</span>);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal">&nbsp;</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; scope.Complete();</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">}</span></p>
<p style="margin: 0in 0in 10pt">You need to reference the System.Transactions assembly and add the namespace &#8216;System.Transactions&#8217;. Also, you need to make sure the windows service-&#8220;Distributed Transaction Coordinator Service&#8221; is running. </p>
<p style="margin: 0in 0in 0pt">Related link:&nbsp;</p>
<p style="margin: 0in 0in 10pt"><a href="http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx">http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx</a></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How can I use left join in LINQ.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> You can use the keywords &#8220;join&#8221; and &#8220;into&#8221; to implement left join in LINQ. Please take a look at following example:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">var</span><span style="font-size: 9pt; font-family: 新宋体"> sel = <span style="color: blue">from</span> u <span style="color: blue">in</span> ctx.Tags</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">join</span> p <span style="color: blue">in</span> ctx.ArticlesTags <span style="color: blue">on</span> u.TagID <span style="color: blue">equals</span> p.TagID <span style="color: blue">into</span> UP</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">from</span> p <span style="color: blue">in</span> UP.DefaultIfEmpty()</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">select</span> <span style="color: blue">new</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UT = u.TagID,</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UT1 = u.Text,</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; UT2 = p.Info</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</span> </p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">What&#8217;s the difference between List&lt;T&gt; and IQueryable&lt;T&gt;?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> You can return LINQ query result as type of both List&lt;T&gt; and IQueryable&lt;T&gt;. But there are some differences between these two types. </p>
<p style="margin: 0in 0in 10pt">List&lt;T&gt; will create a new list object in memory immediately to persist data. If there&#8217;re any associations in this table, the related information will be null. But IQueryable&lt;T&gt; will not retrieve the data until you iterate the data source &#8211; use foreach, databind, ToList and so on. When there&#8217;s an association in this table, the related information will not be null and can be used. Please take a look at following example to understand the differences between them.</p>
<p style="margin: 0in 0in 0pt">// Return List&lt;T&gt; will fail when referring to related UserInfos object</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">List</span><span style="font-size: 9pt; font-family: 新宋体">&lt;<span style="color: #2b91af">User</span>&gt; users = res.ToList&lt;<span style="color: #2b91af">User</span>&gt;();</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; color: blue; line-height: 115%; font-family: 新宋体">var</span><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体"> ss = users.Where&lt;<span style="color: #2b91af">User</span>&gt;(p =&gt; p.UserInfos.ID != 3);</span></p>
<p style="margin: 0in 0in 0pt">// Return IQueryable&lt;T&gt; will be successful</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">IQueryable</span><span style="font-size: 9pt; font-family: 新宋体">&lt;<span style="color: #2b91af">User</span>&gt; users = res.AsQueryable&lt;<span style="color: #2b91af">User</span>&gt;();</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; color: blue; line-height: 115%; font-family: 新宋体">var</span><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体"> ss = users.Where&lt;<span style="color: #2b91af">User</span>&gt;(p =&gt; p.UserInfos.ID != 3);</span></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to implement &#8216;Like&#8217; operation in LINQ just like in SQL script?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> If you want to implement the &#8216;Like&#8217; function in LINQ as in SQL script, you can achieve this by following two methods. </p>
<p style="margin: 0in 0in 10pt">First, you can use Contains, StartsWith, or EndsWith method, here is an example to demonstrate how to use them.</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">var</span><span style="font-size: 9pt; font-family: 新宋体"> dd = <span style="color: blue">from</span> p <span style="color: blue">in</span> ctx.Users</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">where</span> p.email.Contains(<span style="color: #a31515">"xx"</span>) || p.userName.StartsWith(<span style="color: #a31515">"xx"</span>) || p.userName.EndsWith(<span style="color: #a31515">"xx"</span>)</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">select</span> p;</span></p>
<p style="margin: 0in 0in 10pt">Second, you can use SqlMethods class, it contains a method named &#8216;Like&#8217; which has the same function with &#8216;Like&#8217; in SQL script.</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">var</span><span style="font-size: 9pt; font-family: 新宋体"> dd = (<span style="color: blue">from</span> p <span style="color: blue">in</span> ctx.Users</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">where</span> <span style="color: #2b91af">SqlMethods</span>.Like(p.userName, <span style="color: #a31515">"%Jiang%"</span>) &amp;&amp; <span style="color: #2b91af">SqlMethods</span>.Like(p.email,<span style="color: #a31515">"%WWW%"</span>)</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">orderby</span> p.accountID</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">select</span> p).Take(10);</span></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to query a DataTable using LINQ?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> LINQ can query the data source which implements interface IEnumerable. This means you need to first call AsEnumerable method on DataTable, and then you can use LINQ to query the data. Here&#8217;s a sample:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">var</span><span style="font-size: 9pt; font-family: 新宋体"> nostr = <span style="color: blue">from</span> u <span style="color: blue">in</span> dt.AsEnumerable()</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">where</span> u.Field&lt;<span style="color: #2b91af">Decimal</span>&gt;(<span style="color: #a31515">"m"</span>).ToString().ToUpper().StartsWith(<span style="color: #a31515">"3"</span>) </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">select</span> <span style="color: blue">new</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MONEY = u.Field&lt;<span style="color: #2b91af">Decimal</span>&gt;(<span style="color: #a31515">"m"</span>),</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TIME = u.Field&lt;<span style="color: #2b91af">DateTime</span>&gt;(<span style="color: #a31515">"t"</span>),</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EXT = <span style="color: #a31515">"Extra Column"</span></span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; };</span></p>
 <img src="http://www.cnblogs.com/David-Qian/aggbug/1383246.html?type=1" width="1" height="1" alt=""/><p>评论: 10　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383246.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383246.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>Data Access FAQ (一)</title><link>http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383241.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Wed, 04 Feb 2009 01:45:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383241.html</guid><description><![CDATA[<p>阅读: 1970 评论: 10 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-02-04 09:45 <a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383241.html" target="_blank">原文链接</a></p><p>前些日子，写了ASP.NET Data Access的FAQ，现在贴出来和大家一起分享，希望对大家有帮助! 这里是第一部分：<br />
<br />
<a title="打包下载" href="http://www.cnblogs.com/Files/David-Qian/Data-Access-FAQ-by-Wencui.rar">打包下载</a></p>
<p style="margin: 24pt 0in 0pt"><strong>Table of Contents</strong></p>
<p style="margin: 0in 0in 5pt"><a href="#_Toc205632899"><strong>General</strong> </a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632900"><strong><span style="font-family: 'Cambria','serif'">How can I set the parameter values of ObjectDataSource in code-behind?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632901"><strong><span style="font-family: 'Cambria','serif'">Comparing DataSet and DataReader.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632902"><strong><span style="font-family: 'Cambria','serif'">How to update the primary key in ObjectDataSource when used with GridView.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632903"><strong><span style="font-family: 'Cambria','serif'">How to call a parameterized stored procedure via ADO.NET.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632904"><strong><span style="font-family: 'Cambria','serif'">Why ObjectDataSource couldn&#8217;t find the type specified in TypeName property.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632905"><strong><span style="font-family: 'Cambria','serif'">How to update all the changes in DataTable/DataSet.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632906"><strong><span style="font-family: 'Cambria','serif'">How can I get the return value when calling stored procedure in typed DataSet?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632907"><strong><span style="font-family: 'Cambria','serif'">What&#8217;s SQL injection? How to avoid that?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632908"><strong><span style="font-family: 'Cambria','serif'">Why I can&#8217;t connect to my database and I also get the error &#8216;connection out of time&#8217;?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632909"><strong><span style="font-family: 'Cambria','serif'">Failed to enable constraints in typed DataSet.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632910"><strong><span style="font-family: 'Cambria','serif'">How to handle slow querying in a database.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632911"><strong><span style="font-family: 'Cambria','serif'">How to select distinct rows in a DataTable.</span></strong></a></p>
<p style="margin: 0in 0in 5pt"><a href="#_Toc205632912"><strong>LINQ</strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632913"><strong><span style="font-family: 'Cambria','serif'">How can I implement a transaction in LINQ?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632914"><strong><span style="font-family: 'Cambria','serif'">How can I use left join in LINQ.</span></strong></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632915"><strong><span style="font-family: 'Cambria','serif'">What&#8217;s the difference between List&lt;T&gt; and IQueryable&lt;T&gt;?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632916"><strong><span style="font-family: 'Cambria','serif'">How to implement &#8216;Like&#8217; operation in LINQ just like in SQL script?</span></strong></span></a></p>
<p style="margin: 0in 0in 5pt 11pt"><a href="#_Toc205632917"><strong><span style="font-family: 'Cambria','serif'">How to query a DataTable using LINQ?</span></strong></span></a></p>
<p style="margin: 0in 0in 10pt">&nbsp;</p>
<p style="margin: 0in 0in 10pt">&nbsp;</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 14pt; color: #548dd4; line-height: 115%">General</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How can I set the parameter values of ObjectDataSource in code-behind?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> Suppose that you want to set the parameters in the Select method of ObjectDataSource. You can handle the Selecting event of ObjectDataSource to set the parameters. For example:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">protected</span><span style="font-size: 9pt; font-family: 新宋体"> <span style="color: blue">void</span> ObjectDataSource1_Selecting(<span style="color: blue">object</span> sender, <span style="color: #2b91af">ObjectDataSourceSelectingEventArgs</span> e)</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">{</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp; e.InputParameters[<span style="color: #a31515">"accountID"</span>] = 5;</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">}</span> </p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">Comparing DataSet and DataReader.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> DataSet is a collection of DataTables and relations between the tables. It is used to hold tables with data, you can select data from tables or create views and access child rows. Also DataSet provides you with rich features like saving data to XML and loading data from XML. DataReader is an object that is used to iterate through a result set that was queried from a server and reads one row per move. If you want forward-only access to the results then DataReader is the best option because it is the most efficient method in this scenario.</p>
<p style="margin: 0in 0in 0pt">Related link:</p>
<p style="margin: 0in 0in 10pt"><a href="http://www.windowsitlibrary.com/Content/1205/06/files/Table3.html">http://www.windowsitlibrary.com/Content/1205/06/files/Table3.html</a></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to update the primary key in ObjectDataSource when used with GridView.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> If you need to update the primary key in Business Logic Layer (BLL), you need to specify DataKeyNames property in GridView control and OldValuesParameterFormatString property in ObjectDataSource control. For example:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">&lt;</span><span style="font-size: 9pt; color: #a31515; font-family: 新宋体">asp</span><span style="font-size: 9pt; color: blue; font-family: 新宋体">:</span><span style="font-size: 9pt; color: #a31515; font-family: 新宋体">ObjectDataSource</span><span style="font-size: 9pt; font-family: 新宋体"> <span style="color: red">ID</span><span style="color: blue">="ObjectDataSource1"</span> <span style="color: red">runat</span><span style="color: blue">="server"</span> </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: red">OldValuesParameterFormatString</span><span style="color: blue">="original_{0}"</span> <span style="color: red">SelectMethod</span><span style="color: blue">="SelectDecs"</span> </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: red">TypeName</span><span style="color: blue">="Job.Code.bll"</span> <span style="color: red">UpdateMethod</span><span style="color: blue">="UpdateDec"&gt;</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">UpdateParameters</span><span style="color: blue">&gt;</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">="original_id"</span> <span style="color: red">Type</span><span style="color: blue">="Int32"</span> <span style="color: blue">/&gt;</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">="id"</span> <span style="color: red">Type</span><span style="color: blue">="Int32"</span> <span style="color: blue">/&gt;</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Parameter</span> <span style="color: red">Name</span><span style="color: blue">="value"</span> <span style="color: red">Type</span><span style="color: blue">="Decimal"</span> <span style="color: blue">/&gt;</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;/</span><span style="color: #a31515">UpdateParameters</span><span style="color: blue">&gt;</span></span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ObjectDataSource</span><span style="color: blue">&gt;</span></span></p>
<p style="margin: 0in 0in 10pt">The signature of the update method in Business Logic Layer is:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">[System.ComponentModel.<span style="color: #2b91af">DataObjectMethod</span>(System.ComponentModel.<span style="color: #2b91af">DataObjectMethodType</span>.Update, <span style="color: blue">true</span>)]</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; color: blue; line-height: 115%; font-family: 新宋体">public</span><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体"> <span style="color: blue">void</span> UpdateDec(<span style="color: blue">int</span> original_id, <span style="color: blue">int</span> id, <span style="color: blue">decimal</span> value)</span><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to call a parameterized stored procedure via ADO.NET.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt">A: When calling a parameterized stored procedure via ADO.NET, you need to set the CommandType property to &#8216;StoredProcedure&#8217;, and correctly set the Direction property when passing parameters into the command. The example below demonstrates how to call a parameterized stored procedure.</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">cmd.CommandType = <span style="color: #2b91af">CommandType</span>.StoredProcedure;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal">&nbsp;</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">SqlParameter</span><span style="font-size: 9pt; font-family: 新宋体"> id = cmd.Parameters.Add(<span style="color: #a31515">"@id"</span>, <span style="color: #2b91af">SqlDbType</span>.Int, 4);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">id.Direction = <span style="color: #2b91af">ParameterDirection</span>.Input;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">SqlParameter</span><span style="font-size: 9pt; font-family: 新宋体"> uName = cmd.Parameters.Add(<span style="color: #a31515">"@uName"</span>,<span style="color: #2b91af">SqlDbType</span>.Char,20);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">uName.Direction = <span style="color: #2b91af">ParameterDirection</span>.Output;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">SqlParameter</span><span style="font-size: 9pt; font-family: 新宋体"> ret = cmd.Parameters.Add(<span style="color: #a31515">"@Return_value"</span>,<span style="color: #2b91af">SqlDbType</span>.Int,4);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">ret.Direction = <span style="color: #2b91af">ParameterDirection</span>.ReturnValue;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">id.Value = 2;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">conn.Open();</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">cmd.ExecuteNonQuery();</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">Response.Write(<span style="color: #a31515">"&lt;br&gt;OutPut Value:"</span> + uName.Value);</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">Response.Write(<span style="color: #a31515">"&lt;br&gt;Return Value:"</span> + ret.Value);</span></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">Why ObjectDataSource couldn&#8217;t find the type specified in TypeName property.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> Please check your project&#8217;s references and ensure the source code or assembly that contains the type is in the right location. The type specified in TypeName property of ObjectDataSource should be in Bin, App_Code or GAC. If your type can&#8217;t be loaded from assemblies in the related directories, a runtime exception will be thrown. </p>
<p style="margin: 0in 0in 0pt">P.S You can also use Fusion log viewer tool to see the binding failures. </p>
<p style="margin: 0in 0in 10pt">Related link: <a href="http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx">http://blogs.msdn.com/suzcook/archive/2003/05/29/57120.aspx</a></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to update all the changes in DataTable/DataSet.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> Usually,<strong> </strong>you can update all the changes in DataTable/DataSet to the database with the help of CommandBuilder object. A CommandBuilder object will help to generate all the changes in DataTable/DataSet to SQL statements which will be executed by the Command object.</p>
<p style="margin: 0in 0in 10pt">To update all the changes to SQL Server, we can write the code as shown below:</p>
<p style="margin: 0in 0in 0pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">da.Fill(ds, <span style="color: #a31515">"tab1"</span>);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">SqlCommandBuilder</span><span style="font-size: 9pt; font-family: 新宋体"> cb = <span style="color: blue">new</span> <span style="color: #2b91af">SqlCommandBuilder</span>(da);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal">&nbsp;</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">ds.Tables[0].Rows[0][<span style="color: #a31515">"username"</span>] = <span style="color: #a31515">"Modified Name"</span>;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">da.UpdateCommand = cb.GetUpdateCommand();</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">da.Update(ds);</span>&nbsp;</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How can I get the return value when calling stored procedure in typed DataSet?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> As we know, the stored procedure is called as a method of a typed DataSet. But when we return a value from a stored procedure, we can&#8217;t get it via the form of &#8216;(int)da.CallSP(xx,xx);&#8217;. If you want to get the return value from a stored procedure, you need to write a new method in the partial class of TableAdapters as shown below &#8211; the input parameter is the index of the method in the TableAdapter which can be easily seen in the designer of typed DataSet.</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: blue; font-family: 新宋体">partial</span><span style="font-size: 9pt; font-family: 新宋体"> <span style="color: blue">class</span> <span style="color: #2b91af">UsersTableAdapter</span></span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">{</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">object</span> GetReturnValue(<span style="color: blue">int</span> commandIndex)</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp; {</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> <span style="color: blue">this</span>.CommandCollection[commandIndex].Parameters[0].Value;</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">&nbsp;&nbsp;&nbsp;&nbsp; }</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">}</span></p>
<p style="margin: 0in 0in 10pt">Then you can call this method to get the return value:</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">da.CallSP(xx, xx);</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; color: blue; line-height: 115%; font-family: 新宋体">int</span><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体"> returnValue = <span style="color: blue">int</span>.Parse(da.GetReturnValue(2).ToString());</span></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">What&#8217;s SQL injection? How to avoid that?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> When you use a string query to build a SQL statement with input values from end-user, it is easy to have a SQL injection attack. For example, we have the following SQL statement to verify a user&#8217;s password:</p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">sql = <span style="color: #a31515">"select * from UserInfo where password='"</span> + password + <span style="color: #a31515">"'"</span>;</span> </p>
<p style="margin: 0in 0in 10pt">A malicious user can use the following input to bypass the password check:</p>
<p style="margin: 0in 0in 10pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">password = <span style="color: #a31515">"' or 1=1 --"</span>;</span></p>
<p style="margin: 0in 0in 10pt">Even worse, some dangerous SQL commands such as &#8220;&#8217;; DROP TABLE &#8230;&#8221; might be executed.</p>
<p style="margin: 0in 0in 10pt">To avoid SQL injection, we can use command parameters in SQL query &#8211; this will be efficient to validate the user. The single quotes will be filtered.</p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">cmd = <span style="color: blue">new</span> <span style="color: #2b91af">SqlCommand</span>(<span style="color: #a31515">"select * from UserInfo where password=@ password"</span>, conn);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; color: #2b91af; font-family: 新宋体">SqlParameter</span><span style="font-size: 9pt; font-family: 新宋体"> pwd = cmd.Parameters.Add(<span style="color: #a31515">"@password"</span>, <span style="color: #2b91af">SqlDbType</span>.Char, 20);</span></p>
<p style="margin: 0in 0in 0pt; line-height: normal"><span style="font-size: 9pt; font-family: 新宋体">pwd.Direction = <span style="color: #2b91af">ParameterDirection</span>.Input;</span></p>
<p style="margin: 0in 0in 10pt"><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">pwd.Value = <span style="color: #a31515">"' or 1=1 --"</span>;</span> </p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">Why I can&#8217;t connect to my database and I also get the error &#8216;connection out of time&#8217;?</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong>A:</strong> The time-out value of SqlConnection or SqlCommand object might be too small.</p>
<p style="margin: 0in 0in 10pt">The default time out of SqlConnection is 15 seconds. You can set this time longer via these two ways.</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Set the ConnectionTimeout property of SqlConnection object.</p>
<p style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Set the Connect Timeout property in the connection string.</p>
<p style="margin: 0in 0in 10pt">The default time out of the SqlCommand is 30 seconds. You can also set this time longer.</p>
<p style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Set the CommandTimeout property of SqlCommand object.</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">Failed to enable constraints in typed DataSet.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 9pt; line-height: 115%; font-family: 新宋体">A:</span></strong> The problem was caused by a discrepancy between the defined max size of a data column in your project's XSD and the size in database. The error is because one of the columns in the database is larger than the one in XSD / table adapter. You can try to update the table schema in XSD or modify the maximum size of a data column manually.</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to handle slow querying in a database.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt; line-height: normal"><strong><span style="font-size: 9pt; font-family: 新宋体">A:</span></strong> There may be several possible causes, here are some general suggestions:</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>Is your table very large? &nbsp;Is it possible to split it into several smaller tables?</p>
<p style="margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; line-height: normal"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>If you don't use all the fields, you could just return the required fields when constructing your SQL statements. Also, you may need to optimize your SQL statements when querying.</p>
<p style="margin: 0in 0in 10pt 0.5in; text-indent: -0.25in; line-height: normal"><span style="font-family: Symbol">&#183;<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span>You may want to index some frequently used fields in database. It'll save you time when querying.</p>
<p style="margin: 0in 0in 10pt"><strong><span style="font-size: 13pt; color: #4f81bd; line-height: 115%; font-family: 'Cambria','serif'">How to select distinct rows in a DataTable.</span></strong><strong></strong></p>
<p style="margin: 0in 0in 10pt; line-height: normal"><strong>A:</strong> As we know, we can use Select method to filter a DataTable based on certain fields. However, it doesn't help to select distinct rows in a DataTable. Therefore, we have no way to select distinct rows directly.</p>
<p style="margin: 0in 0in 0pt; line-height: normal">After a hard research on MSDN, I found a solution here: </p>
<p style="margin: 0in 0in 0pt; line-height: normal"><a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3633630&amp;SiteID=1">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=3633630&amp;SiteID=1</a></p>
<p style="margin: 0in 0in 10pt; line-height: normal">First, create a DataView for your table, and apply any filtering and sorting in that dataview.&nbsp; If you have no filtering or sorting, you can just use originalTable.DefaultView.</p>
<p style="margin: 0in 0in 10pt; line-height: normal">Second, call ToTable() on the dataview.&nbsp; ToTable() has an overload which lets you specify whether or not to return only distinct values, and a params string[] argument to specify which columns you want in the new table.&nbsp; If you specify true as the first argument, only rows unique within the columns that you specify in the params argument will be returned.&nbsp; If you want all of the columns from the original table, you can simply specify the boolean argument "true"; if you don't specify any columns, all columns are returned.</p>
<p style="margin: 0in 0in 10pt; line-height: normal">Thus, the easiest way to return a new table that has only the unique values from the original table is as follows:</p>
<p style="margin: 0in 0in 10pt; line-height: normal"><span style="font-size: 10pt; color: #2b91af; font-family: 宋体">DataTable</span><span style="font-size: 10pt; font-family: 宋体"> distinctTable = originalTable.DefaultView.ToTable( <span style="color: green">/*distinct*/</span> <span style="color: blue">true</span>);</span></p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1383241.html?type=1" width="1" height="1" alt=""/><p>评论: 10　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383241.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/02/04/1383241.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>web.config 文件加密</title><link>http://www.cnblogs.com/David-Qian/archive/2009/01/23/1380355.html</link><dc:creator>Wencui</dc:creator><author>Wencui</author><pubDate>Fri, 23 Jan 2009 05:19:00 GMT</pubDate><guid>http://www.cnblogs.com/David-Qian/archive/2009/01/23/1380355.html</guid><description><![CDATA[<p>阅读: 484 评论: 0 作者: <a href="http://www.cnblogs.com/David-Qian/" target="_blank">Wencui</a> 发表于 2009-01-23 13:19 <a href="http://www.cnblogs.com/David-Qian/archive/2009/01/23/1380355.html" target="_blank">原文链接</a></p><p>一般来说，我们是需要对web.config文件中的一些敏感信息加密的。通常如下节点会考虑加密，除此之外，很多节点通常都不会被加密，甚至于不能被加密：</p>
<p>1) &lt;appSettings&gt;&nbsp; 一般包含一些我们自定义的信息。<br />
2) &lt;connectionStrings&gt;&nbsp; 这个大家比较熟悉，包含连接数据库用的字符串。<br />
3) &lt;identity&gt;&nbsp; 包含使用impersonate时的账户信息。<br />
4) &lt;sessionState&gt;&nbsp; 包含将session置于process外的连接字符串。</p>
<p>提到加密，我们一般有会想用什么算法加密，怎么样来加密。第一个问题，ASP.NET提供了两种加密方式，DPAPI和RSA。我们可以选择其中一种方式来加密我们的web.config。第二个问题，我们同样也有两种方式，利用aspnet_regiis.exe工具或在程序中用代码加密。</p>
<p>首先，先谈谈使用aspnet_regiis.exe加密的一些命令。先打开Visual Studio的命令行窗口，然后输入 aspnet_regiis /?，我们可以查看关于aspnet_regiis的一些帮助信息。此例中，我们使用DPAPI来加密connectionStrings，website在IIS的sample1虚拟目录中：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aspnet_regiis -pe "connectionStrings" -app "/sample1" -prov "DataProtectionConfigurationProvider"</p>
<p>如果我们的website还没用publish到IIS中，我们可以使用如下命令来加密 - 给出website的绝对路径：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aspnet_regiis -pef "connectionStrings" C:\Projects\sample1 &#8211;prov "DataProtectionConfigurationProvider"</p>
<p>这样一个简单的加密就完成了。在获取这些加密信息时，我们可以使用如下代码，它可以自动帮我们解密：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string connStr = ConfigurationManager.ConnectionStrings["test"].ConnectionString;</p>
<p>如果你想将加密的节点改回原来的状态，你可以使用-pd参数：</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;aspnet_regiis -pd "connectionStrings" -app "/sample1" </p>
<p>&nbsp;</p>
<p>同样，我们也可以在程序用进行加密解密。</p>
<p>加密：</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_130828" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_130828').style.display='none'; document.getElementById('Code_Open_Image_130828').style.display='inline'; document.getElementById('Code_Open_Text_130828').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_130828" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_130828').style.display='none'; getElementById('Code_Closed_Image_130828').style.display='inline'; getElementById('Code_Closed_Text_130828').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_130828">Code</span><span id="Code_Open_Text_130828" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Get&nbsp;the&nbsp;current&nbsp;configuration&nbsp;file.</span><span style="color: #008000"><br />
</span><span style="color: #000000">Configuration&nbsp;config&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);<br />
<br />
</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Get&nbsp;the&nbsp;section.</span><span style="color: #008000"><br />
</span><span style="color: #000000">ConfigurationSection&nbsp;appSec&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;config.GetSection(</span><span style="color: #800000">"</span><span style="color: #800000">appSettings</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(appSec&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">!</span><span style="color: #000000">appSec.SectionInformation.IsProtected)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Protect&nbsp;(encrypt)the&nbsp;section.</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;appSec.SectionInformation.ProtectSection(</span><span style="color: #800000">"</span><span style="color: #800000">DataProtectionConfigurationProvider</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #008000">//</span><span style="color: #008000">&nbsp;Save&nbsp;the&nbsp;encrypted&nbsp;section.</span><span style="color: #008000"><br />
</span><span style="color: #000000">&nbsp;&nbsp;&nbsp;&nbsp;appSec.SectionInformation.ForceSave&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">true</span><span style="color: #000000">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;config.Save();<br />
}</span></span></div>
<p>解密：</p>
<div class="cnblogs_code"><img id="Code_Closed_Image_130928" onclick="this.style.display='none'; document.getElementById('Code_Closed_Text_130928').style.display='none'; document.getElementById('Code_Open_Image_130928').style.display='inline'; document.getElementById('Code_Open_Text_130928').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif" width="11" align="top"><img id="Code_Open_Image_130928" style="display: none" onclick="this.style.display='none'; document.getElementById('Code_Open_Text_130928').style.display='none'; getElementById('Code_Closed_Image_130928').style.display='inline'; getElementById('Code_Closed_Text_130928').style.display='inline';" height="16" src="http://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif" width="11" align="top"><span class="cnblogs_code_Collapse" id="Code_Closed_Text_130928">Code</span><span id="Code_Open_Text_130928" style="display: none"><br />
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000">Configuration&nbsp;config&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);<br />
<br />
ConfigurationSection&nbsp;section&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;config.GetSection(</span><span style="color: #800000">"</span><span style="color: #800000">appSettings</span><span style="color: #800000">"</span><span style="color: #000000">);<br />
<br />
</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(section&nbsp;</span><span style="color: #000000">!=</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">null</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">&amp;&amp;</span><span style="color: #000000">&nbsp;section.SectionInformation.IsProtected)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;section.SectionInformation.UnprotectSection();<br />
&nbsp;&nbsp;&nbsp;&nbsp;config.Save();<br />
}</span></span></div>
<p>&nbsp;</p>
<p>不过有一点要注意，当你将加密后的website移到另一台IIS上时它是不能进行解密的，因为加密的key是放在本地机器的。此时你需要在另一台server上重新使用aspnet_regiis进行加密。</p>
<p>RSA和DPAPI有点不同。DPAPI的key是难以导出的，而RAS的key是容易导出的。这表明我们可以在本地使用RSA进行加密，然后把这个key导出，并安装到server上就可以直接进行解密了。</p>
<p>Have a nice day!</p>
<img src="http://www.cnblogs.com/David-Qian/aggbug/1380355.html?type=1" width="1" height="1" alt=""/><p>评论: 0　<a href="http://www.cnblogs.com/David-Qian/archive/2009/01/23/1380355.html#pagedcomment" target="_blank">查看评论</a>　<a href="http://www.cnblogs.com/David-Qian/archive/2009/01/23/1380355.html#commentform" target="_blank">发表评论</a></p><hr/><p>最新新闻：<br/>· <a href="http://news.cnblogs.com/n/56841/" target="_blank">2010年度技术奖获得者评选揭晓</a><span style="color:gray">(2010-02-10 14:45)</span><br/>· <a href="http://news.cnblogs.com/n/56840/" target="_blank">Google宣布三个产品来帮助广告商的收入最大</a><span style="color:gray">(2010-02-10 14:42)</span><br/>· <a href="http://news.cnblogs.com/n/56839/" target="_blank">软件工程师的谎言</a><span style="color:gray">(2010-02-10 14:39)</span><br/>· <a href="http://news.cnblogs.com/n/56838/" target="_blank">谷歌联合创始人谈Buzz：可以分享实时位置</a><span style="color:gray">(2010-02-10 14:28)</span><br/>· <a href="http://news.cnblogs.com/n/56837/" target="_blank">Android命名 冻酸奶之后是姜饼</a><span style="color:gray">(2010-02-10 14:11)</span><br/></p><p>编辑推荐：<a href="http://news.cnblogs.com/n/56829/" target="_blank">.NET Reflector即将商业化</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>