﻿<?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>BlogJava-AndyZhang-随笔分类-ASP.NET</title><link>http://www.blogjava.net/AndyZhang/category/49333.html</link><description>welcome to java world</description><language>zh-cn</language><lastBuildDate>Mon, 14 May 2012 11:28:37 GMT</lastBuildDate><pubDate>Mon, 14 May 2012 11:28:37 GMT</pubDate><ttl>60</ttl><item><title>导出excel表（将数据库里的数据表保存为xls的文件）</title><link>http://www.blogjava.net/AndyZhang/archive/2012/05/14/378120.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Mon, 14 May 2012 08:39:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2012/05/14/378120.html</guid><description><![CDATA[<div>1.先得出一个表Table。<br />2.在代码中建一个excel实例。<br />&nbsp;&nbsp; 在建实例前先引用<font face="Verdana">Microsoft.Office.Interop.Excel</font>组件&#8212;&#8212;添加引用<br />&nbsp;&nbsp; Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();<br />&nbsp;&nbsp;&nbsp;excel.Workbooks.Add(true);<br />3.将table时的数据，循环遍历插入到excel中。<br /><br />具体实例如下：<br /><font face="Verdana">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string connectionstr = "Server=192.168.1.10;database=ssh;uid=sa;pwd=1234";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string sqlstr = "select * from medstock";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection con = new SqlConnection(connectionstr);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand(sqlstr,con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataTable db = new DataTable();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter adp = new SqlDataAdapter(cmd);//由于SqlDataAdapter自身带有数据库打开与关闭功能，所以不用手动打开数据库与关闭。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; adp.Fill(ds,"table1");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db = ds.Tables["table1"];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//建列名，根据实际情况而定，即要在excel中显示的列名；<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string[] str=new string[db.Columns.Count];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; str.Length-2; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; str[i] = db.Columns[i+1].ColumnName;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //建excel实例。也就是table的容器；<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; excel.Workbooks.Add(true);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //先在excel中显示出table的列名；<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; str.Length; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excel.Cells[1, i + 1] = str[i];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //再向excel中循环添加表中的每一行的每一列；<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (db.Rows.Count &gt; 0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int i = 0; i &lt; db.Rows.Count; i++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for (int j = 1; j &lt; db.Columns.Count; j++)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str1 = db.Rows[i][j].ToString();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; excel.Cells[i + 2, j] = "'" + str1;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //设置禁止弹出保存和覆盖的询问提示框&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// excel.DisplayAlerts = false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// excel.AlertBeforeOverwriting = false;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excel.Save();//保存excel文件 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; excel.Quit();//确保Excel进程关闭<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excel.Visible = true;// 前台可见 后台运行<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;excel = null;<br /><br /></font></div><img src ="http://www.blogjava.net/AndyZhang/aggbug/378120.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2012-05-14 16:39 <a href="http://www.blogjava.net/AndyZhang/archive/2012/05/14/378120.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>!page.ispostback 的意思,用法！</title><link>http://www.blogjava.net/AndyZhang/archive/2012/05/01/377129.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Tue, 01 May 2012 14:46:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2012/05/01/377129.html</guid><description><![CDATA[<p>!Page.IsPostBack，表示页面首次加载,还有按钮默认是回发服务器的，所以点击按钮页面会刷新。
</p>
<p>&nbsp; &nbsp; 控件都是服务器端的控件, 如果你的控件设为自动回发到服务器（即AutoPostBack属性设为True），执行每次操作都会提交到后台处理(就是所谓的后台代码，即以[.aspx.cs]结尾的页面),也就要在再次加载页面的同时做出相应的操作，所以先再次执行page_load事件，执行了
if(!page.IsPostBack){}外的代码
后再执行其它的操作（你在页面上的操作）。处理完再回发到，即跳转到相应的页面。如果还是回发到原来的页面，则这时候该页面就不是第一次加载了，而是俗称的回传页。</p>
<p>&nbsp; &nbsp; &nbsp; 把 if(!page.IsPostBack){ 这里是首次加载页面时要实现的功能代码；} 代码写在page_load事件中。<span style="color: red">还</span><span style="color: red">可以使用if(!IsPostBack)来判断&#8212;&#8212;是否是当前页面控件的操作 ！！</span></p>
<img src ="http://www.blogjava.net/AndyZhang/aggbug/377129.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2012-05-01 22:46 <a href="http://www.blogjava.net/AndyZhang/archive/2012/05/01/377129.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>winfrom与asp.net的区别</title><link>http://www.blogjava.net/AndyZhang/archive/2012/04/16/374730.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Mon, 16 Apr 2012 06:24:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2012/04/16/374730.html</guid><wfw:comment>http://www.blogjava.net/AndyZhang/comments/374730.html</wfw:comment><comments>http://www.blogjava.net/AndyZhang/archive/2012/04/16/374730.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/AndyZhang/comments/commentRss/374730.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/AndyZhang/services/trackbacks/374730.html</trackback:ping><description><![CDATA[<div>1. winform中可以运用缓存吗？<br />&nbsp;&nbsp;&nbsp; <span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">所谓缓存，是把获取或生成比较麻烦的结果性的东西，在内存中暂存。WinForm和ASP.NET的实现机制不同，建议不要在WinForm中使用System.Web.Caching。实际上，string s=streamReader1.ReadToEnd()，s变量本身就已经缓存了streamReader1所对应的文件内容，这样实现缓存就可以了。<br />&nbsp;&nbsp;&nbsp;&nbsp; <span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">winform的东西基本都在内存了，你还要什么缓存啊？</span><br style="word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" /><span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">cache是把编译后的网页存放在内存中，有人请求时不用重新编译，这样节约资源。<span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">如果用的是winform，基本上不用想这个问题，因为你的程序本身就在内存里运行着。</span><br style="word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px" /><span style="display: inline! important; float: none; word-spacing: 0px; font: 12px/18px Tahoma; text-transform: none; color: rgb(0,0,0); text-indent: 0px; white-space: normal; letter-spacing: normal; text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">如果是web，缓存就是将常用的数据放到服务器的内存中，当有不同的客户请求相同的数据时，直接从内存读取，以此提高性能。</span></span></span></div><img src ="http://www.blogjava.net/AndyZhang/aggbug/374730.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2012-04-16 14:24 <a href="http://www.blogjava.net/AndyZhang/archive/2012/04/16/374730.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Asp.net日期字符串格式化显示--DateTime.ToString()用法详解</title><link>http://www.blogjava.net/AndyZhang/archive/2012/04/13/374039.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Fri, 13 Apr 2012 02:39:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2012/04/13/374039.html</guid><description><![CDATA[<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">我们经常会遇到对时间进行转换,达到不同的显示效果，默认格式为:2006-6-6 14:33:34<span class="Apple-converted-space">&nbsp;</span><br />如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢？<br />这里将要用到:<strong>DateTime.ToString</strong>的方法<strong>(String, IFormatProvider)<br />示例：<br /></strong>using System;<br />using System.Globalization;<br />String format="D";<br />DateTime date=DataTime.Now;<br />Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));<br />结果输出<br />Thursday, June 16, 2006<br /><br />在这里列出了参数format格式详细用法<br />=======================<br />格式字符 关联属性/说明<span class="Apple-converted-space">&nbsp;</span><br />d ShortDatePattern<span class="Apple-converted-space">&nbsp;</span><br />D LongDatePattern<span class="Apple-converted-space">&nbsp;</span><br />f 完整日期和时间（长日期和短时间）<span class="Apple-converted-space">&nbsp;</span><br />F FullDateTimePattern（长日期和长时间）<span class="Apple-converted-space">&nbsp;</span><br />g 常规（短日期和短时间）<span class="Apple-converted-space">&nbsp;</span><br />G 常规（短日期和长时间）<span class="Apple-converted-space">&nbsp;</span><br />m、M MonthDayPattern<span class="Apple-converted-space">&nbsp;</span><br />r、R RFC1123Pattern<span class="Apple-converted-space">&nbsp;</span><br />s 使用当地时间的 SortableDateTimePattern（基于 ISO 8601）<span class="Apple-converted-space">&nbsp;</span><br />t ShortTimePattern<span class="Apple-converted-space">&nbsp;</span><br />T LongTimePattern<span class="Apple-converted-space">&nbsp;</span><br />u UniversalSortableDateTimePattern 用于显示通用时间的格式<span class="Apple-converted-space">&nbsp;</span><br />U 使用通用时间的完整日期和时间（长日期和长时间）<span class="Apple-converted-space">&nbsp;</span><br />y、Y YearMonthPattern</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">下表列出了可被合并以构造自定义模式的模式<br />========================================<br />这些模式是区分大小写的；例如，识别&#8220;MM&#8221;，但不识别&#8220;mm&#8221;。如果自定义模式包含空白字符或用单引号括起来的字符，则输出字符串页也将包含这些字符。未定义为格式模式的一部分或未定义为格式字符的字符按其原义复制。</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">格式模式 说明 ：<br />d 月中的某一天。一位数的日期没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />dd 月中的某一天。一位数的日期有一个前导零。<span class="Apple-converted-space">&nbsp;</span><br />ddd 周中某天的缩写名称，在 AbbreviatedDayNames 中定义。<span class="Apple-converted-space">&nbsp;</span><br />dddd 周中某天的完整名称，在 DayNames 中定义。<span class="Apple-converted-space">&nbsp;</span><br />M 月份数字。一位数的月份没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />MM 月份数字。一位数的月份有一个前导零。<span class="Apple-converted-space">&nbsp;</span><br />MMM 月份的缩写名称，在 AbbreviatedMonthNames 中定义。<span class="Apple-converted-space">&nbsp;</span><br />MMMM 月份的完整名称，在 MonthNames 中定义。<span class="Apple-converted-space">&nbsp;</span><br />y 不包含纪元的年份。如果不包含纪元的年份小于 10，则显示不具有前导零的年份。<span class="Apple-converted-space">&nbsp;</span><br />yy 不包含纪元的年份。如果不包含纪元的年份小于 10，则显示具有前导零的年份。<span class="Apple-converted-space">&nbsp;</span><br />yyyy 包括纪元的四位数的年份。<span class="Apple-converted-space">&nbsp;</span><br />gg 时期或纪元。如果要设置格式的日期不具有关联的时期或纪元字符串，则忽略该模式。<span class="Apple-converted-space">&nbsp;</span><br />h 12 小时制的小时。一位数的小时数没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />hh 12 小时制的小时。一位数的小时数有前导零。<span class="Apple-converted-space">&nbsp;</span><br />H 24 小时制的小时。一位数的小时数没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />HH 24 小时制的小时。一位数的小时数有前导零。<span class="Apple-converted-space">&nbsp;</span><br />m 分钟。一位数的分钟数没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />mm 分钟。一位数的分钟数有一个前导零。<span class="Apple-converted-space">&nbsp;</span><br />s 秒。一位数的秒数没有前导零。<span class="Apple-converted-space">&nbsp;</span><br />ss 秒。一位数的秒数有一个前导零。<span class="Apple-converted-space">&nbsp;</span><br />f 秒的小数精度为一位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />ff 秒的小数精度为两位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />fff 秒的小数精度为三位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />ffff 秒的小数精度为四位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />fffff 秒的小数精度为五位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />ffffff 秒的小数精度为六位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />fffffff 秒的小数精度为七位。其余数字被截断。<span class="Apple-converted-space">&nbsp;</span><br />t 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项的第一个字符（如果存在）。<span class="Apple-converted-space">&nbsp;</span><br />tt 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项（如果存在）。<span class="Apple-converted-space">&nbsp;</span><br />z 时区偏移量（&#8220;+&#8221;或&#8220;-&#8221;后面仅跟小时）。一位数的小时数没有前导零。例如，太平洋标准时间是&#8220;-8&#8221;。<span class="Apple-converted-space">&nbsp;</span><br />zz 时区偏移量（&#8220;+&#8221;或&#8220;-&#8221;后面仅跟小时）。一位数的小时数有前导零。例如，太平洋标准时间是&#8220;-08&#8221;。<span class="Apple-converted-space">&nbsp;</span><br />zzz 完整时区偏移量（&#8220;+&#8221;或&#8220;-&#8221;后面跟有小时和分钟）。一位数的小时数和分钟数有前导零。例如，太平洋标准时间是&#8220;-08:00&#8221;。<span class="Apple-converted-space">&nbsp;</span><br />: 在 TimeSeparator 中定义的默认时间分隔符。<span class="Apple-converted-space">&nbsp;</span><br />/ 在 DateSeparator 中定义的默认日期分隔符。<span class="Apple-converted-space">&nbsp;</span><br />% c 其中 c 是格式模式（如果单独使用）。如果格式模式与原义字符或其他格式模式合并，则可以省略&#8220;%&#8221;字符。<br />/ c 其中 c 是任意字符。照原义显示字符。若要显示反斜杠字符，请使用&#8220;//&#8221;。</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">只有上面第二个表中列出的格式模式才能用于创建自定义模式；在第一个表中列出的标准格式字符不能用于创建自定义模式。自定义模式的长度至少为两个字符；例如，</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">DateTime.ToString( "d") 返回 DateTime 值；&#8220;d&#8221;是标准短日期模式。<span class="Apple-converted-space">&nbsp;</span><br />DateTime.ToString( "%d") 返回月中的某天；&#8220;%d&#8221;是自定义模式。<span class="Apple-converted-space">&nbsp;</span><br />DateTime.ToString( "d ") 返回后面跟有一个空白字符的月中的某天；&#8220;d&#8221;是自定义模式。</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">比较方便的是,上面的参数可以随意组合,并且不会出错,多试试,肯定会找到你要的时间格式<br />如要得到2005年06月 这样格式的时间<br />可以这样写:<br />date.ToString("yyyy年MM月", DateTimeFormatInfo.InvariantInfo)<br />如此类推.<br /><br />下面列出一些Asp.net中具体的日期格式化用法：<br />============================================<br />1.绑定时格式化日期方法:<span class="Apple-converted-space">&nbsp;</span><br />&lt;ASP:BOUNDCOLUMN DATAFIELD= "JoinTime " DATAFORMATSTRING= "{0:yyyy-MM-dd} " &gt;<span class="Apple-converted-space">&nbsp;</span><br />&lt;ITEMSTYLE WIDTH= "18% " &gt; &lt;/ITEMSTYLE &gt;<span class="Apple-converted-space">&nbsp;</span><br />&lt;/ASP:BOUNDCOLUMN &gt;</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">2.数据控件如DataGrid/DataList等的件格式化日期方法:<span class="Apple-converted-space">&nbsp;</span><br />e.Item.Cell[0].Text = Convert.ToDateTime(e.Item.Cell[0].Text).ToShortDateString();</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">3.用String类转换日期显示格式:<span class="Apple-converted-space">&nbsp;</span><br />String.Format( "yyyy-MM-dd ",yourDateTime);</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">4.用Convert方法转换日期显示格式:<span class="Apple-converted-space">&nbsp;</span><br />Convert.ToDateTime("2005-8-23").ToString</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">("yyMMdd",System.Globalization.DateTimeFormatInfo.InvariantInfo); //支持繁体数据库</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">5.直接用ToString方法转换日期显示格式:<span class="Apple-converted-space">&nbsp;</span><br />DateTime.Now.ToString("yyyyMMddhhmmss");<span class="Apple-converted-space">&nbsp;</span><br />DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss")</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">6.只显示年月<span class="Apple-converted-space">&nbsp;</span><br />DataBinder.Eval(Container.DataItem,"starttime","{0:yyyy-M}")</p>
<p style="word-spacing: 0px; font: 14px/26px Arial; text-transform: none; color: rgb(51,51,51); text-indent: 0px; white-space: normal; letter-spacing: normal; background-color: rgb(255,255,255); text-align: left; orphans: 2; widows: 2; webkit-text-size-adjust: auto; webkit-text-stroke-width: 0px">7.显示时间所有部分，包括：年月日时分秒<span class="Apple-converted-space">&nbsp;</span><br />&lt;asp:BoundColumn DataField="收款时间" HeaderText="收款时间"<span class="Apple-converted-space">&nbsp;</span><br />DataFormatString="{0:yyyy-MM-dd HH24:mm:ss}"&gt;<span class="Apple-converted-space">&nbsp;</span><br />&lt;/asp:BoundColumn&gt;</p> <img src ="http://www.blogjava.net/AndyZhang/aggbug/374039.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2012-04-13 10:39 <a href="http://www.blogjava.net/AndyZhang/archive/2012/04/13/374039.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>winform 中往数据库中添加图片的两种方式</title><link>http://www.blogjava.net/AndyZhang/archive/2011/09/08/358267.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Thu, 08 Sep 2011 02:01:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2011/09/08/358267.html</guid><description><![CDATA[<span class="Apple-style-span" style="color: #999999; font-family: verdana; font-size: 12px; line-height: 18px; background-color: #10100f; "><p><span style="color: #000000; "><strong>方法一：在数据库中添加图片名字，然后把图片存在指定的文件夹中</strong></span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 这种方法存起来简单，但是删除的时候麻烦。</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 存：在数据库中建一个文本字段（access）或者varchar字段（sqlserver）长度能放上一张图片即可</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 过程：就是一般的存的insert into&nbsp;</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;举个栗子：sql数据库中有一个id字段 自增类型 一个name字段，用于存放图片名称的类型是varchar类型</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;这winform界面中你可以拖动一个TextBox，用于存放路径，一个Button这个就不说了，还有一个openFileDialog</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (this.openFileDialog1.ShowDialog() == DialogResult.OK)</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; this.textBox1.Text = openFileDialog1.FileName;</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} //打开路径，必不可少的 &nbsp; &nbsp; 这些都是是在button单击事件里完成的</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (openFileDialog1.FileName.Length &gt; 0)&nbsp;// 判断openFileDialog1路径的长度</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string oldName = openFileDialog1.FileName; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//定义一个string类型的变量 用于存放【文件路径】</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string[] splitName = oldName.Split('.'); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //为获取文件的扩展名做准备的</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string ext = splitName[splitName.Length - 1]; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//文件的扩展名</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (ext == "jpg" || ext == "gif" || ext == "bmp" || ext == "JPG") &nbsp; //限制上传图片的格式</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;string dbName = DateTime.Now.ToString("yyyyMMddhhmmss") + "." + ext; //给上传的图片起个名字！以时间命名</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string newName = AppDomain.CurrentDomain.BaseDirectory &nbsp;+ dbName; &nbsp;//新路径!这是个相对路径</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;File.Copy(oldName, newName, true); &nbsp;//把文件从以前的路径复制到新的路径中去</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //下面就开始添加到数据库里面了</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string constring="";//数据库的连接字符串</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (SqlConnection con=new SqlConnection (constring))</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con.open();</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stirng sql="insert into shujukuname (name) values(@name)"; //因为id自增的这里只需要添加图片名称</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;SqlCommand cmd = new SqlCommand(sql,con);</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmd.Parameters.Add("@name",SqlDbType.VarChar).Value=TextBox1.Text.Trim();</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cmd.ExecuteNonQuery();</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;con.Close();</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这样就添加完成了</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;显示图片： &nbsp;这里一定要有一个PictureBox1</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;要从数据库中取出这个name</span></p><p><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;using (SqlConnection con=new SqlConnection (constring))</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;string sql="select name from shujukuname where id=' 1' &nbsp; ";//当id=1的时候查询的图片的名称</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;SqlDataAdapter da = new SqlDataAdapter(sql, con);</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; con.Open();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DataTable dt=new &nbsp;DataTable();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; da.Fill(dt);</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string name =dt.Rows[0]["name"].ToString();</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; con.Close(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//这样就获取出name来了，然后进行显示</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string path=Application.StartupPath + "//"+ name; &nbsp;//一张图片的路径</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(File.Exists(path)) //根据这个路劲显示有没有这张图片</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PictureBox1.Image=Image.FromFile(path); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//PictureBox1显示的path路径的图片</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;PictureBox1.Image=Image.FromFile(Application.StartupPath + "//" +默认图片); &nbsp;//PictureBox1显示的默认的的图片</span></p><p style="margin-top: 10px; margin-bottom: 10px; "><span style="color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}</span></p></span><span class="Apple-style-span" style="color: #999999; font-family: verdana; font-size: 12px; line-height: 18px; background-color: #10100f; "><p><span style="color: #000000; "><strong>winform 中往数据库中添加图片的两种方式之二：直接把图片添加在sqlserver中</strong></span></p><p><span style="color: #000000; ">首先要有一个image或者binary类型的字段</span></p><p><span style="color: #000000; ">这种是以二进制形式插入到数据库中</span></p><p><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #00ff00; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileStream fs = new FileStream(pathName, System.IO.FileMode.Open, System.IO.FileAccess.Read);<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;byte[] buffByte = new byte[fs.Length];<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fs.Read(buffByte, 0, (int)fs.Length);<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fs.Close(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//</span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">数据库字段为image类型，将图片转化为byte[]，保存到数据库</span><br />&nbsp;&nbsp; &nbsp; &nbsp;<br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlConnection &nbsp; db &nbsp; = &nbsp; new &nbsp; SqlConnection(strConn);&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; db.Open();&nbsp;<br /><br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string &nbsp; strSQL &nbsp; = &nbsp; "INSERT &nbsp; INTO &nbsp; shujuktable (name) &nbsp; values &nbsp; (@name) ";&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCommand &nbsp; cmd &nbsp; = &nbsp; new &nbsp; SqlCommand(strSQL, &nbsp; db);&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.Parameters.Add( "@name", &nbsp; SqlDbType.Image);&nbsp;<br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.Parameters[ "@name"].Value &nbsp; = &nbsp;&nbsp;<span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">buffByte</span></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">;&nbsp;<br /><br /></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cmd.ExecuteNonQuery(); &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //保存图片的过程</span></p><p><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #000000; ">清理资源</span></p><p><span face="Tahoma, Helvetica, Arial, serif" style="font-family: Tahoma, Helvetica, Arial, serif; color: #00ff00; "><span class="Apple-style-span" style="line-height: 20px; color: #000000; ">以上这部分是如何添加图片，下面这部分是读取图片</span></span></p><p><span face="Tahoma, Helvetica, Arial, serif" style="font-family: Tahoma, Helvetica, Arial, serif; color: #00ff00; "><span class="Apple-style-span" style="line-height: 20px; color: #000000; ">-&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></span></p><p><span style="color: #00ff00; "><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlConnection conn = new SqlConnection(</span></span><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; line-height: 20px; color: #000000; ">strConn</span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; line-height: 21px; color: #000000; ">);</span></span></p><p><span class="Apple-style-span" style="font-family: Tahoma, Helvetica, Arial, serif; font-size: 14px; line-height: 21px; color: #00ff00; "><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; "><br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; DataTable dt = new DataTable();<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; SqlDataAdapter adp = new SqlDataAdapter("select name from shujuktable where ID='1'", conn);<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; adp.Fill(dt);<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; byte[] buffByte = (byte[])dt.Rows[0][&#8220;name&#8221;];<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; MemoryStream ms = new MemoryStream(buffByte);<br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; Image image = Image.FromStream(ms, true);<br style="word-wrap: break-word; line-height: normal; " /><br style="word-wrap: break-word; line-height: normal; " /></span><span class="Apple-style-span" style="border-collapse: collapse; font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 14px; line-height: 22px; color: #000000; ">&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.pictureEdit1.Image = image;</span></span></p></span><img src ="http://www.blogjava.net/AndyZhang/aggbug/358267.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2011-09-08 10:01 <a href="http://www.blogjava.net/AndyZhang/archive/2011/09/08/358267.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用连接字符串</title><link>http://www.blogjava.net/AndyZhang/archive/2011/09/08/358265.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Thu, 08 Sep 2011 01:46:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2011/09/08/358265.html</guid><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 有关 .NET 数据提供程序的连接字符串关键字的更多信息，请参见ConnectionString连接字符串关键字连接字符串的格式是使用分号分隔的键/值参数对列表：keyword1=value; keyword2=value忽略空格，关键字不区分大小写，尽管值可能会区分大小写，这取决于数据源的大小写。要加入包含分号、单引号或双引号的值，值必须加双引号。&nbsp;有关 .NET 数据提供程序的连...&nbsp;&nbsp;<a href='http://www.blogjava.net/AndyZhang/archive/2011/09/08/358265.html'>阅读全文</a><img src ="http://www.blogjava.net/AndyZhang/aggbug/358265.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2011-09-08 09:46 <a href="http://www.blogjava.net/AndyZhang/archive/2011/09/08/358265.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#中的@符号</title><link>http://www.blogjava.net/AndyZhang/archive/2011/08/27/357398.html</link><dc:creator>SkyDream</dc:creator><author>SkyDream</author><pubDate>Sat, 27 Aug 2011 04:23:00 GMT</pubDate><guid>http://www.blogjava.net/AndyZhang/archive/2011/08/27/357398.html</guid><description><![CDATA[<font size="2">&nbsp;</font> 
<div><font size="2">C#中的@符号其实有很多的用法，我们来看看@有什么神奇之处。</font>&nbsp;</div>
<div><span class="Title"><strong><font color="#4169e1" size="4">1.限定字符串</font></strong></span></div>
<div><font size="2">用 @ 符号加在字符串前面表示其中的转义字符&#8220;不&#8221;被处理。</font></div>
<div><font size="2">如果我们写一个文件的路径，例如"D:\文本文件"路径下的text.txt文件，不加@符号的话写法如下：</font></div>
<div style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-bottom: 4px; padding-left: 5.4pt; width: 95%; padding-right: 5.4pt;background: #e6e6e6; word-break: break-all; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 4px">
<div><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;fileName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">D:\\文本文件\\text.txt";</span></font></div></div>
<div><font size="2"></font>&nbsp;<font size="2">如果使用@符号就会比较简单：</font></div>
<div style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-bottom: 4px; padding-left: 5.4pt; width: 95%; padding-right: 5.4pt;background: #e6e6e6; word-break: break-all; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 4px">
<div><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;fileName&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">@"</span><span style="color: #000000">D:\文本文件\text.txt</span><span style="color: #000000">"</span><span style="color: #000000">;<img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /></span></font></div></div>
<div><span class="Title"><font size="2"></font></span><br />&nbsp;<span class="Title"><font size="2"><font color="#4169e1"><font size="4"><strong>2.让字符串跨行</strong></font></font></font></span></div>
<div><font size="2">有时候一个字符串写在一行中会很长(比如SQL语句)，不使用@符号，一种写法是这样的：</font> </div>
<div style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-bottom: 4px; padding-left: 5.4pt; width: 95%; padding-right: 5.4pt;background: #e6e6e6; word-break: break-all; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 4px">
<div><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;strSQL&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">SELECT&nbsp;*&nbsp;FROM&nbsp;HumanResources.Employee&nbsp;AS&nbsp;e</span><span style="color: #000000">"</span></font><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</font></span><font size="2"><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;INNER&nbsp;JOIN&nbsp;Person.Contact&nbsp;AS&nbsp;c</span><span style="color: #000000">"</span></font><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</font></span><font size="2"><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;ON&nbsp;e.ContactID&nbsp;=&nbsp;c.ContactID</span><span style="color: #000000">"</span></font><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</font></span><font size="2"><span style="color: #000000">+</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">"</span><span style="color: #000000">&nbsp;ORDER&nbsp;BY&nbsp;c.LastName</span><span style="color: #000000">"</span><span style="color: #000000">;</span></font></div></div>
<div><font size="2"></font>&nbsp;<font size="2">加上@符号后就可以直接换行了：</font></div>
<div style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-bottom: 4px; padding-left: 5.4pt; width: 95%; padding-right: 5.4pt;background: #e6e6e6; word-break: break-all; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 4px">
<div><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: #0000ff">string</span><span style="color: #000000">&nbsp;strSQL&nbsp;</span><span style="color: #000000">=</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">@"</span></font><font size="2"><span style="color: #000000">SELECT&nbsp;*&nbsp;FROM&nbsp;HumanResources.Employee&nbsp;AS&nbsp;e<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;INNER&nbsp;JOIN&nbsp;Person.Contact&nbsp;AS&nbsp;c<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;ON&nbsp;e.ContactID&nbsp;=&nbsp;c.ContactID<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" />&nbsp;&nbsp;&nbsp;&nbsp;ORDER&nbsp;BY&nbsp;c.LastName</span><span style="color: #000000">"</span><span style="color: #000000">;</span></font></div></div>
<div><span class="Title"><font size="2"></font></span>&nbsp;<br /><span class="Title"><font size="2"><font color="#4169e1"><strong><font size="4">3.在标识符中的用法</font></strong></font></font></span></div>
<div><font size="2">C#是不允许关键字作为标识符(类名、变量名、方法名、表空间名等)使用的，但如果加上@之后就可以了，例如：</font>&nbsp;</div>
<div style="border-bottom: windowtext 0.5pt solid; border-left: windowtext 0.5pt solid; padding-bottom: 4px; padding-left: 5.4pt; width: 95%; padding-right: 5.4pt;background: #e6e6e6; word-break: break-all; border-top: windowtext 0.5pt solid; border-right: windowtext 0.5pt solid; padding-top: 4px">
<div><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif" /><span style="color: #0000ff">namespace</span></font><font size="2"><span style="color: #000000">&nbsp;@namespace<br /><img id="_21_450_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif" /><img style="display: none" id="_21_450_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif" /></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_21_450_Closed_Text">...</span></font><span id="_21_450_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">class</span></font><font size="2"><span style="color: #000000">&nbsp;@class<br /><img id="_44_448_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img style="display: none" id="_44_448_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_44_448_Closed_Text">...</span></font><span id="_44_448_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">public</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">static</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">void</span><span style="color: #000000">&nbsp;@static(</span><span style="color: #0000ff">int</span></font><font size="2"><span style="color: #000000">&nbsp;@int)<br /><img id="_99_442_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img style="display: none" id="_99_442_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_99_442_Closed_Text">...</span></font><span id="_99_442_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(@int&nbsp;</span><span style="color: #000000">&gt;</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span></font><font size="2"><span style="color: #000000">)<br /><img id="_139_215_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img style="display: none" id="_139_215_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_139_215_Closed_Text">...</span></font><span id="_139_215_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">Positive&nbsp;Integer</span><span style="color: #000000">"</span></font><span style="color: #000000"><font size="2">);<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></span></span><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span><font size="2"><span style="color: #0000ff">else</span><span style="color: #000000">&nbsp;</span><span style="color: #0000ff">if</span><span style="color: #000000">&nbsp;(@int&nbsp;</span><span style="color: #000000">==</span><span style="color: #000000">&nbsp;</span><span style="color: #000000">0</span></font><font size="2"><span style="color: #000000">)<br /><img id="_261_325_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img style="display: none" id="_261_325_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_261_325_Closed_Text">...</span></font><span id="_261_325_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">Zero</span><span style="color: #000000">"</span></font><span style="color: #000000"><font size="2">);<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></span></span><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span><span style="color: #0000ff"><font size="2">else</font></span><span style="color: #000000"><br /><font size="2"><img id="_356_432_Open_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif" /><img style="display: none" id="_356_432_Closed_Image" alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></span><span style="border-bottom: #808080 1px solid; border-left: #808080 1px solid; background-color: #ffffff; display: none; border-top: #808080 1px solid; border-right: #808080 1px solid" id="_356_432_Closed_Text"><font size="2">...</font></span><span id="_356_432_Open_Text"><font size="2"><span style="color: #000000">{<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.Console.WriteLine(</span><span style="color: #000000">"</span><span style="color: #000000">Negative&nbsp;Integer</span><span style="color: #000000">"</span></font><span style="color: #000000"><font size="2">);<br /><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></span></span><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</font></span></span><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif" />&nbsp;&nbsp;&nbsp;&nbsp;}</font></span></span><span style="color: #000000"><br /><font size="2"><img alt="" align="top" src="http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif" />}</font></span></span></div></div><img src ="http://www.blogjava.net/AndyZhang/aggbug/357398.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/AndyZhang/" target="_blank">SkyDream</a> 2011-08-27 12:23 <a href="http://www.blogjava.net/AndyZhang/archive/2011/08/27/357398.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>