﻿<?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>IT博客-青蛙學堂-随笔分类-軟件布袋</title><link>http://www.cnitblog.com/yide/category/1524.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 13 Aug 2020 22:31:05 GMT</lastBuildDate><pubDate>Thu, 13 Aug 2020 22:31:05 GMT</pubDate><ttl>60</ttl><item><title>php上传文件类型</title><link>http://www.cnitblog.com/yide/archive/2016/06/01/90446.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Wed, 01 Jun 2016 08:09:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2016/06/01/90446.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/90446.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2016/06/01/90446.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/90446.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/90446.html</trackback:ping><description><![CDATA[网上有很多php文件上传的类，文件上传处理是php的一个特色(至少手册上是将此作为php特点来展示的,个人认为php在数组方面的优异功能更有特色)，学php的人都知道文件上传怎么做，但很多人在编程中却可能忽视了一些细节问题，那就是文件的类型(MIME)。在表单将文件提交给php做处理之前，浏览器会先解析识别一边是什么类型的文件，之后进入php处理环节，php又会去识别解析此文件的原始类型(并不是说你改成什么后缀就是什么文件)。在这个过程中会有一些浏览器兼容，更准确来说是文件类型解析标识不一致的问题。这样在php处理Post过来的文件类型时就需要根据不同浏览器做更多的判断，最典型的就是IE和火狐下的区别。 <br /><br />　　php上传图片文件(gif,jpg,bmp,png,psd,ico) <br /><br />史上最完全oophper亲测版php文件上传之文件类型对应表，ie，火狐各一份。 <br /><br />
<table border="0" cellspacing="0" bordercolor="#000000" cellpadding="0" width="100%">
<tbody>
<tr>
<td align="center">ie</td>
<td align="center">火狐</td></tr>
<tr>
<td align="center">
<table border="1" cellspacing="1" bordercolor="#000000" cellpadding="1" width="100%">
<thead>
<tr>
<th>id</th>
<th>后缀名</th>
<th>php识别出的文件类型</th></tr></thead>
<tbody>
<tr>
<td>0</td>
<td>gif</td>
<td>image/gif</td></tr>
<tr>
<td>1</td>
<td>jpg</td>
<td>image/jpeg</td></tr>
<tr>
<td>2</td>
<td>png</td>
<td>image/png</td></tr>
<tr>
<td>3</td>
<td>bmp</td>
<td>image/bmp</td></tr>
<tr>
<td>4</td>
<td>psd</td>
<td>application/octet-stream</td></tr>
<tr>
<td>5</td>
<td>ico</td>
<td>image/x-icon</td></tr>
<tr>
<td>6</td>
<td>rar</td>
<td>application/octet-stream</td></tr>
<tr>
<td>7</td>
<td>zip</td>
<td>application/zip</td></tr>
<tr>
<td>8</td>
<td>7z</td>
<td>application/octet-stream</td></tr>
<tr>
<td>9</td>
<td>exe</td>
<td>application/octet-stream</td></tr>
<tr>
<td>10</td>
<td>avi</td>
<td>video/avi</td></tr>
<tr>
<td>11</td>
<td>rmvb</td>
<td>application/vnd.rn-realmedia-vbr</td></tr>
<tr>
<td>12</td>
<td>3gp</td>
<td>application/octet-stream</td></tr>
<tr>
<td>13</td>
<td>flv</td>
<td>application/octet-stream</td></tr>
<tr>
<td>14</td>
<td>mp3</td>
<td>audio/mpeg</td></tr>
<tr>
<td>15</td>
<td>wav</td>
<td>audio/wav</td></tr>
<tr>
<td>16</td>
<td>krc</td>
<td>application/octet-stream</td></tr>
<tr>
<td>17</td>
<td>lrc</td>
<td>application/octet-stream</td></tr>
<tr>
<td>18</td>
<td>txt</td>
<td>text/plain</td></tr>
<tr>
<td>19</td>
<td>doc</td>
<td>application/msword</td></tr>
<tr>
<td>20</td>
<td>xls</td>
<td>application/vnd.ms-excel</td></tr>
<tr>
<td>21</td>
<td>ppt</td>
<td>application/vnd.ms-powerpoint</td></tr>
<tr>
<td>22</td>
<td>pdf</td>
<td>application/pdf</td></tr>
<tr>
<td>23</td>
<td>chm</td>
<td>application/octet-stream</td></tr>
<tr>
<td>24</td>
<td>mdb</td>
<td>application/msaccess</td></tr>
<tr>
<td>25</td>
<td>sql</td>
<td>application/octet-stream</td></tr>
<tr>
<td>26</td>
<td>con</td>
<td>application/octet-stream</td></tr>
<tr>
<td>27</td>
<td>log</td>
<td>text/plain</td></tr>
<tr>
<td>28</td>
<td>dat</td>
<td>application/octet-stream</td></tr>
<tr>
<td>29</td>
<td>ini</td>
<td>application/octet-stream</td></tr>
<tr>
<td>30</td>
<td>php</td>
<td>application/octet-stream</td></tr>
<tr>
<td>31</td>
<td>html</td>
<td>text/html</td></tr>
<tr>
<td>32</td>
<td>htm</td>
<td>text/html</td></tr>
<tr>
<td>33</td>
<td>ttf</td>
<td>application/octet-stream</td></tr>
<tr>
<td>34</td>
<td>fon</td>
<td>application/octet-stream</td></tr>
<tr>
<td>35</td>
<td>js</td>
<td>application/x-javascript</td></tr>
<tr>
<td>36</td>
<td>xml</td>
<td>text/xml</td></tr>
<tr>
<td>37</td>
<td>dll</td>
<td>application/octet-stream</td></tr>
<tr>
<td>38</td>
<td>dll</td>
<td>application/octet-stream</td></tr></tbody></table></td>
<td align="center">
<table border="1" cellspacing="1" bordercolor="#000000" cellpadding="1" width="100%">
<thead>
<tr>
<th>id</th>
<th>后缀名</th>
<th>php识别出的文件类型</th></tr></thead>
<tbody>
<tr>
<td>0</td>
<td>gif</td>
<td>image/gif</td></tr>
<tr>
<td>1</td>
<td>jpg</td>
<td>image/pjpeg</td></tr>
<tr>
<td>2</td>
<td>png</td>
<td>image/x-png</td></tr>
<tr>
<td>3</td>
<td>bmp</td>
<td>image/bmp</td></tr>
<tr>
<td>4</td>
<td>psd</td>
<td>application/octet-stream</td></tr>
<tr>
<td>5</td>
<td>ico</td>
<td>image/x-icon</td></tr>
<tr>
<td>6</td>
<td>rar</td>
<td>application/octet-stream</td></tr>
<tr>
<td>7</td>
<td>zip</td>
<td>application/x-zip-compressed</td></tr>
<tr>
<td>8</td>
<td>7z</td>
<td>application/octet-stream</td></tr>
<tr>
<td>9</td>
<td>exe</td>
<td>application/octet-stream</td></tr>
<tr>
<td>10</td>
<td>avi</td>
<td>video/avi</td></tr>
<tr>
<td>11</td>
<td>rmvb</td>
<td>application/vnd.rn-realmedia-vbr</td></tr>
<tr>
<td>12</td>
<td>3gp</td>
<td>application/octet-stream</td></tr>
<tr>
<td>13</td>
<td>flv</td>
<td>application/octet-stream</td></tr>
<tr>
<td>14</td>
<td>mp3</td>
<td>audio/mpeg</td></tr>
<tr>
<td>15</td>
<td>wav</td>
<td>audio/wav</td></tr>
<tr>
<td>16</td>
<td>krc</td>
<td>application/octet-stream</td></tr>
<tr>
<td>17</td>
<td>lrc</td>
<td>application/octet-stream</td></tr>
<tr>
<td>18</td>
<td>txt</td>
<td>text/plain</td></tr>
<tr>
<td>19</td>
<td>doc</td>
<td>application/msword</td></tr>
<tr>
<td>20</td>
<td>xls</td>
<td>application/vnd.ms-excel</td></tr>
<tr>
<td>21</td>
<td>ppt</td>
<td>application/vnd.ms-powerpoint</td></tr>
<tr>
<td>22</td>
<td>pdf</td>
<td>application/pdf</td></tr>
<tr>
<td>23</td>
<td>chm</td>
<td>application/octet-stream</td></tr>
<tr>
<td>24</td>
<td>mdb</td>
<td>application/msaccess</td></tr>
<tr>
<td>25</td>
<td>sql</td>
<td>text/plain</td></tr>
<tr>
<td>26</td>
<td>con</td>
<td>application/octet-stream</td></tr>
<tr>
<td>27</td>
<td>log</td>
<td>text/plain</td></tr>
<tr>
<td>28</td>
<td>dat</td>
<td>text/plain</td></tr>
<tr>
<td>29</td>
<td>ini</td>
<td>application/octet-stream</td></tr>
<tr>
<td>30</td>
<td>php</td>
<td>application/octet-stream</td></tr>
<tr>
<td>31</td>
<td>html</td>
<td>text/html</td></tr>
<tr>
<td>32</td>
<td>htm</td>
<td>text/html</td></tr>
<tr>
<td>33</td>
<td>ttf</td>
<td>application/octet-stream</td></tr>
<tr>
<td>34</td>
<td>fon</td>
<td>application/octet-stream</td></tr>
<tr>
<td>35</td>
<td>js</td>
<td>text/html</td></tr>
<tr>
<td>36</td>
<td>xml</td>
<td>text/xml</td></tr>
<tr>
<td>37</td>
<td>dll</td>
<td>application/octet-stream</td></tr>
<tr>
<td>38</td>
<td>class</td>
<td>application/java</td></tr></tbody></table></td></tr></tbody></table>* application/octet-stream //应用程序 <br />323 text/h323 <br />acx application/internet-property-stream <br />ai application/postscript <br />aif audio/x-aiff <br />aifc audio/x-aiff <br />aiff audio/x-aiff <br />asf video/x-ms-asf <br />asr video/x-ms-asf <br />asx video/x-ms-asf <br />au audio/basic <br />avi video/x-msvideo <br />axs application/olescript <br />bas text/plain <br />bcpio application/x-bcpio <br />bin application/octet-stream <br />bmp image/bmp <br />c text/plain <br />cat application/vnd.ms-pkiseccat <br />cdf application/x-cdf <br />cer application/x-x509-ca-cert <br />class application/octet-stream <br />clp application/x-msclip <br />cmx image/x-cmx <br />cod image/cis-cod <br />cpio application/x-cpio <br />crd application/x-mscardfile <br />crl application/pkix-crl <br />crt application/x-x509-ca-cert <br />csh application/x-csh <br />css text/css <br />dcr application/x-director <br />der application/x-x509-ca-cert <br />dir application/x-director <br />dll application/x-msdownload <br />dms application/octet-stream <br />doc application/msword <br />dot application/msword <br />dvi application/x-dvi <br />dxr application/x-director <br />eps application/postscript <br />etx text/x-setext <br />evy application/envoy <br />exe application/octet-stream <br />fif application/fractals <br />flr x-world/x-vrml <br />gif image/gif <br />gtar application/x-gtar <br />gz application/x-gzip <br />h text/plain <br />hdf application/x-hdf <br />hlp application/winhlp <br />hqx application/mac-binhex40 <br />hta application/hta <br />htc text/x-component <br />htm text/html <br />html text/html <br />htt text/webviewhtml <br />ico image/x-icon <br />ief image/ief <br />iii application/x-iphone <br />ins application/x-internet-signup <br />isp application/x-internet-signup <br />jfif image/pipeg <br />jpe image/jpeg <br />jpeg image/jpeg <br />jpg image/jpeg <br />jpg image/pjpeg <br />js application/x-javascript <br />latex application/x-latex <br />lha application/octet-stream <br />lsf video/x-la-asf <br />lsx video/x-la-asf <br />lzh application/octet-stream <br />m13 application/x-msmediaview <br />m14 application/x-msmediaview <br />m3u audio/x-mpegurl <br />man application/x-troff-man <br />mdb application/x-msaccess <br />me application/x-troff-me <br />mht message/rfc822 <br />mhtml message/rfc822 <br />mid audio/mid <br />mny application/x-msmoney <br />mov video/quicktime <br />movie video/x-sgi-movie <br />mp2 video/mpeg <br />mp3 audio/mpeg <br />mpa video/mpeg <br />mpe video/mpeg <br />mpeg video/mpeg <br />mpg video/mpeg <br />mpp application/vnd.ms-project <br />mpv2 video/mpeg <br />ms application/x-troff-ms <br />mvb application/x-msmediaview <br />nws message/rfc822 <br />oda application/oda <br />p10 application/pkcs10 <br />p12 application/x-pkcs12 <br />p7b application/x-pkcs7-certificates <br />p7c application/x-pkcs7-mime <br />p7m application/x-pkcs7-mime <br />p7r application/x-pkcs7-certreqresp <br />p7s application/x-pkcs7-signature <br />pbm image/x-portable-bitmap <br />pdf application/pdf <br />pfx application/x-pkcs12 <br />pgm image/x-portable-graymap <br />pko application/ynd.ms-pkipko <br />pma application/x-perfmon <br />pmc application/x-perfmon <br />pml application/x-perfmon <br />pmr application/x-perfmon <br />pmw application/x-perfmon <br />png image/x-png <br />pnm image/x-portable-anymap <br />pot, application/vnd.ms-powerpoint <br />ppm image/x-portable-pixmap <br />pps application/vnd.ms-powerpoint <br />ppt application/vnd.ms-powerpoint <br />prf application/pics-rules <br />ps application/postscript <br />pub application/x-mspublisher <br />qt video/quicktime <br />ra audio/x-pn-realaudio <br />ram audio/x-pn-realaudio <br />ras image/x-cmu-raster <br />rgb image/x-rgb <br />rmi audio/mid <br />roff application/x-troff <br />rtf application/rtf <br />rtx text/richtext <br />scd application/x-msschedule <br />sct text/scriptlet <br />setpay application/set-payment-initiation <br />setreg application/set-registration-initiation <br />sh application/x-sh <br />shar application/x-shar <br />sit application/x-stuffit <br />snd audio/basic <br />spc application/x-pkcs7-certificates <br />spl application/futuresplash <br />src application/x-wais-source <br />sst application/vnd.ms-pkicertstore <br />stl application/vnd.ms-pkistl <br />stm text/html <br />sv4cpio application/x-sv4cpio <br />sv4crc application/x-sv4crc <br />t application/x-troff <br />tar application/x-tar <br />tcl application/x-tcl <br />tex application/x-tex <br />texi application/x-texinfo <br />texinfo application/x-texinfo <br />tgz application/x-compressed <br />tif image/tiff <br />tiff image/tiff <br />tr application/x-troff <br />trm application/x-msterminal <br />tsv text/tab-separated-values <br />txt text/plain <br />uls text/iuls <br />ustar application/x-ustar <br />vcf text/x-vcard <br />vrml x-world/x-vrml <br />wav audio/x-wav <br />wcm application/vnd.ms-works <br />wdb application/vnd.ms-works <br />wks application/vnd.ms-works <br />wmf application/x-msmetafile <br />wps application/vnd.ms-works <br />wri application/x-mswrite <br />wrl x-world/x-vrml <br />wrz x-world/x-vrml <br />xaf x-world/x-vrml <br />xbm image/x-xbitmap <br />xla application/vnd.ms-excel <br />xlc application/vnd.ms-excel <br />xlm application/vnd.ms-excel <br />xls application/vnd.ms-excel <br />xlt application/vnd.ms-excel <br />xlw application/vnd.ms-excel <br />xof x-world/x-vrml <br />xpm image/x-xpixmap <br />xwd image/x-xwindowdump <br />z application/x-compress <br />zip application/zip -firefox <br />application/x-zip-compressed -IE <br /><br /><br />　　php上传压缩文件(rar,7z,zip) <br /><br />　　php上传可执行文件(exe) <br /><br />　　php上传视频文件,音乐文件,歌词文件(avi,rmvb,3gp,flv,mp3,wav,krc,lrc) <br /><br />　　php上传文本文件和文档文件(word-&gt;doc,excel-&gt;xls,幻灯片-&gt;ppt,pdf,chm) <br /><br />　　php上传数据库文件(access文件,sql文件,con文件,日志文件log, dat文件) <br /><br />　　php上传网页文件,脚本文件,字体文件(ini,php,html,htm,字体文件：ttf,fon, js ,xml) <br /><br />　　php上传其他文件(class类文件,dll动态加载库文件) <img src ="http://www.cnitblog.com/yide/aggbug/90446.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2016-06-01 16:09 <a href="http://www.cnitblog.com/yide/archive/2016/06/01/90446.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FW:结识正能量，跟对人 </title><link>http://www.cnitblog.com/yide/archive/2014/04/03/89393.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 03 Apr 2014 09:45:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2014/04/03/89393.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/89393.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2014/04/03/89393.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/89393.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/89393.html</trackback:ping><description><![CDATA[<header class="entry-header">&nbsp; 
<h1 class="entry-title"><a href="http://www.xiaobapo.com/?p=8" rel="bookmark">结识正能量，跟对人</a> </h1><!-- .comments-link --></header><!-- .entry-header -->

<div class="entry-content">
<p>&#8220;沙子是废物，水泥也是废物，但他们混在一起是混凝土，就是精品；大米是精品，汽油也是精品，但他们混在一起就是废物。是精品还是废物不重要，跟谁混，很重要! ＂</p>
<p>&nbsp;朋友不是乱交的，每天在一起喝酒的不一定是真朋友，每天在一起混的也不一定是永远的朋友。人生要交的四位朋友：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;<br />1、交一个欣赏你的朋友，即便在你穷困潦倒的时候反而会更安慰你、帮助你。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;<br />2、交一个有正能量的朋友，在你情绪低落的时候陪伴你、鼓励你。&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;<br />3、交一个为你领路的朋友，自愿做你的垫脚石，带你走过泥泞、拨开迷雾。&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p>
<p>&nbsp;<br />4、交一个肯指点你的朋友，时刻提醒你、监督你，让你时刻发现自己的不足。!财富不是永远的朋友，朋友却是永远的财富</p></div><img src ="http://www.cnitblog.com/yide/aggbug/89393.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2014-04-03 17:45 <a href="http://www.cnitblog.com/yide/archive/2014/04/03/89393.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#--释放资源--事务</title><link>http://www.cnitblog.com/yide/archive/2012/04/17/78986.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 17 Apr 2012 00:32:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/04/17/78986.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78986.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/04/17/78986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78986.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78986.html</trackback:ping><description><![CDATA[<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore"><font face="Calibri">1.</font><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">开启资源应注意尽早释放，关闭</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">第一种方式：</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Try</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">{ </font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp; </span>Conn.open();</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Calibri">&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">具体处理部分</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">}</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Catch(sqlException ex)</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">{</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;</span>}</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Finally</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">{</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;</span>Conn.close();</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">}</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore"><font face="Calibri">2.</font><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">使用</span><span lang="EN-US"><font face="Calibri">using </font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">语句块</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Using (sqlconnection conn = new sqlconnection( connectstring) )</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">{</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;</span>Conn.open() ;</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">具体处理语句；</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">}</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">最好以上两种方式结合使用；</span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font face="Calibri">3.</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">利用事务块处理</span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;&nbsp; </span>Using (Transactionscope scope = new TransactionScope( TransactionScopeOption.Required))</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>{</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><span style="mso-spacerun: yes"><font face="Calibri">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </font></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">具体处理语句；</span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>Scope.complete () ;</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>}</font></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: -18pt; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0; mso-list: l0 level1 lfo1" class="MsoListParagraph"><span style="mso-fareast-font-family: Calibri; mso-fareast-theme-font: minor-latin; mso-bidi-font-family: Calibri; mso-bidi-theme-font: minor-latin" lang="EN-US"><span style="mso-list: Ignore"><font face="Calibri">3.</font><span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">调用存储过程</span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Create procedure regionupdate (@regionid interger , @regiondescription nchar(50)) as</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Set nocount off</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Update region</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri"><span style="mso-spacerun: yes">&nbsp;&nbsp; </span>Set regiondescription = @regiondescription</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Where region = @regionid</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Go</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">Sqlcommand cmd = new sqlcommand(&#8220;</font></span><span style="font-family: 宋体; mso-ascii-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-fareast-font-family: 宋体; mso-fareast-theme-font: minor-fareast; mso-hansi-font-family: Calibri; mso-hansi-theme-font: minor-latin">过程名</span><span lang="EN-US"><font face="Calibri">&#8221; , conn);</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">cmd.commandtype = commandtype.storedprocedure ;</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">cmd.parameters.addwithvalue(&#8220;</font><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#64;&#116;&#101;&#103;&#105;&#111;&#110;&#105;&#100;&#8221;&#44;&#50;&#51;&#41;"><u><font color="#0000ff" face="Calibri">@tegionid&#8221;,23)</font></u></a><font face="Calibri">;</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">cmd.parameters.addwithvalue(&#8220;</font><a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#64;&#116;&#101;&#103;&#105;&#111;&#110;&#105;&#100;&#8221;&#44;&#50;&#51;&#41;"><u><font color="#0000ff" face="Calibri">@tegiondescription&#8221;,&#8221;something&#8221;)</font></u></a><font face="Calibri">;</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="display: none; mso-hide: all" lang="EN-US"><font face="Calibri">,23);<o:p></o:p></font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span style="display: none; mso-hide: all" lang="EN-US"><font face="Calibri">nid"ters.addwithvalue(".storedprocedure ;egiondescription Option.Required))<o:p></o:p></font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><font face="Calibri"></font></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><font face="Calibri">cmd.executenonquery();</font></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="text-indent: 0cm; margin: 0cm 0cm 0pt 18pt; mso-char-indent-count: 0" class="MsoListParagraph"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p>
<p style="margin: 0cm 0cm 0pt" class="MsoNormal"><span lang="EN-US"><o:p><font face="Calibri">&nbsp;</font></o:p></span></p><img src ="http://www.cnitblog.com/yide/aggbug/78986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-04-17 08:32 <a href="http://www.cnitblog.com/yide/archive/2012/04/17/78986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c#方法参数</title><link>http://www.cnitblog.com/yide/archive/2012/03/18/78153.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Sun, 18 Mar 2012 13:02:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/18/78153.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78153.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/18/78153.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78153.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78153.html</trackback:ping><description><![CDATA[<p align="left">C#语言的方法可以使用如下四种参数(请注意和参数类型的区别)：</p> <p align="left">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  值参数，不含任何修饰符。</p> <p align="left">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  引用参数，以ref修饰符声明。</p> <p align="left">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  输出参数，以out修饰符声明。</p> <p align="left">l&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  数组参数，以params修饰符声明。</p> <p align="left">1．&nbsp;  值参数</p> <p align="left">当用值参数向方法传递参数时，程序给实参的值做一份拷贝，并且将此拷贝传递给该方法，被调用的方法不会修改实参的值，所以使用值参数时，可以保证实参的值是安全的。如果参数类型是引用类型，例如是类的引用变量，则拷贝中存储的也是对象的引用，所以拷贝和实参引用同一个对象，通过这个拷贝，可以修改实参所引用的对象中的数据成员。</p> <p align="left">2．&nbsp;  引用参数</p> <p align="left">有时在方法中，需要修改或得到方法外部的变量值，C语言用向方法传递实参指针来达到目的，C#语言用引用参数。当用引用参数向方法传递实参时，程序将把实参的引用，即实参在内存中的地址传递给方法，方法通过实参的引用，修改或得到方法外部的变量值。引用参数以ref修饰符声明。注意在使用前，实参变量要求必须被设置初始值。</p> <p align="left">3．&nbsp;  输出参数</p> <p align="left">为了把方法的运算结果保存到外部变量，因此需要知道外部变量的引用(地址)。输出参数用于向方法传递外部变量引用(地址)，所以输出参数也是引用参数，与引用参数的差别在于调用方法前无需对变量进行初始化。在方法返回后，传递的变量被认为经过了初始化。值参数、引用参数和输出参数的使用见下例：</p> <p align="left">using System;</p> <p align="left">class g{public int a=0;}//类定义</p> <p align="left">class Class1</p> <p align="left">{&nbsp;&nbsp; public static void F1(ref char  i)//引用参数</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  i='b';}</p> <p align="left">&nbsp;&nbsp;&nbsp; public static void F2(char  i)//值参数，参数类型为值类型</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  i='d';}</p> <p align="left">&nbsp;&nbsp;&nbsp; public static void F3(out char  i)//输出参数</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  i='e';}</p> <p align="left">public static void F4(string  s)//值参数，参数类型为字符串</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  s="xyz";}</p> <p align="left">&nbsp;&nbsp;&nbsp; public static void F5(g  gg)//值参数，参数类型为引用类型</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  gg.a=20;}</p> <p align="left">public static void F6(ref string  s)//引用参数，参数类型为字符串</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  s="xyz";}</p> <p align="left">&nbsp;&nbsp;&nbsp; static void Main(string[]  args)</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; char  a='c';</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string s1="abc";</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F2(a);//值参数，不能修改外部的a</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(a);//因a未被修改，显示c</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F1(ref  a);//引用参数,函数修改外部的a的值</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(a);//a被修改为b，显示b</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Char j;</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F3(out  j);//输出参数，结果输出到外部变量j</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(j);//显示e</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F4(s1);//值参数，参数类型是字符串，s1为字符串引用变量</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(s1);//显示：abc,字符串s1不被修改</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g g1=new g();</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F5(g1);//值参数，但实参是一个类引用类型变量</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(g1.a.ToString());//显示:20，修改对象数据</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F6(ref  s1);//引用参数，参数类型是字符串，s1为字符串引用变量</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine(s1);//显示：xyz，字符串s1被修改</p> <p align="left">&nbsp;&nbsp;&nbsp; }</p> <p align="left">}</p> <p align="left">4．&nbsp;  数组参数</p> <p align="left">数组参数使用params说明，如果形参表中包含了数组参数，那么它必须是参数表中最后一个参数，数组参数只允许是一维数组。比如string[]和string[][]类型都可以作为数组型参数。最后，数组型参数不能再有ref和out修饰符。见下例：</p> <p align="left">using System;</p> <p align="left">class Class1</p> <p align="left">{&nbsp;&nbsp; static void F(params int[]  args)//数组参数，有params说明</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  Console.Write("Array contains {0} elements:",args.Length);</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (int i in  args)</p> <p align="left">Console.Write(" {0}",i);</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine();</p> <p align="left">&nbsp;&nbsp;&nbsp; }</p> <p align="left">&nbsp;&nbsp;&nbsp; static void Main(string[]  args)</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; int[] a =  {1,2,3};</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F(a);//实参为数组类引用变量a</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F(10, 20, 30,  40);//等价于F(new int[]  {60,70,80,90});</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F(new int[]  {60,70,80,90});//实参为数组类引用</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F();//等价于F(new int[] {});</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F(new int[]  {});//实参为数组类引用，数组无元素</p> <p align="left">&nbsp;&nbsp;&nbsp; }</p> <p align="left">}</p> <p align="left">程序输出</p> <p align="left">Array contains 3 elements: 1 2 3</p> <p align="left">Array contains 4 elements: 10 20 30 40</p> <p align="left">Array contains 4 elements: 60,70,80,90</p> <p align="left">Array contains 0 elements:</p> <p align="left">Array contains 0 elements:</p> <p align="left">&nbsp;&nbsp;&nbsp;  方法的参数为数组时也可以不使用params，此种方法可以使用一维或多维数组，见下例：</p> <p align="left">using System;</p> <p align="left">class Class1</p> <p align="left">{&nbsp;&nbsp; static void F(int[,] args)//值参数，参数类型为数组类引用变量，无params说明</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;  Console.Write("Array contains {0} elements:",args.Length);</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; foreach (int i in  args)</p> <p align="left">Console.Write(" {0}",i);</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  Console.WriteLine();</p> <p align="left">&nbsp;&nbsp;&nbsp; }</p> <p align="left">&nbsp;&nbsp;&nbsp; static void Main(string[]  args)</p> <p align="left">&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp; int[,] a =  {{1,2,3},{4,5,6}};</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  F(a);//实参为数组类引用变量a</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //F(10, 20, 30,  40);//此格式不能使用</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; F(new int[,]  {{60,70},{80,90}});//实参为数组类引用</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  //F();//此格式不能使用</p> <p align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //F(new int[,] {});//此格式不能使用</p> <p align="left">&nbsp;&nbsp;&nbsp; }</p> <p align="left">}</p> <p align="left">程序输出</p> <p align="left">Array contains 3 elements: 1 2 3 4 5 6</p> <p align="left">Array contains 4 elements: 60,70,80,90</p> <img src ="http://www.cnitblog.com/yide/aggbug/78153.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-18 21:02 <a href="http://www.cnitblog.com/yide/archive/2012/03/18/78153.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c#方法和函数</title><link>http://www.cnitblog.com/yide/archive/2012/03/18/78152.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Sun, 18 Mar 2012 12:39:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/18/78152.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78152.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/18/78152.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78152.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78152.html</trackback:ping><description><![CDATA[<p>都用来实现一定的功能（甚至什么也不执行）；不同点在于：通常方法作为一个特定类（抽象类或实例类）的成员而存在，而函数则既可以被类包含，也可以独立于某个类。</p> <p>&nbsp;</p> <p>如果你是c/c++背景的程序员，那以前叫函数的东西现在c#叫方法。如果c#是你的第一个语言，忘记函数吧，在c#里没有函数的概念，都叫方法</p> <p>&nbsp;</p> <p>C＃中没有函数这一概念了，都是方法<br />函数是独立存在的（非面向对象），可以直接调用<br />而方法是依存于对象的（面向对象编程），必须使用：对象.方法，来调用<br />如果方法在对象体中，则可以直接调用</p> <p>&nbsp;</p> <p>构造函数是和类名相同的方法，在创建类的实例时构造这个类的方法。不用调用，自动执行的。<br />成员方法是你自己定义的方法。调用时用class.methodname();</p> <p>&nbsp;</p> <p>函数和方法没有本质区别，但是通常自己写的实现特定功能的代码块叫做方法，比如你写了一个类，定义了几个方法，很少说定义了几个函数。由系统间接或直接生成的不完整代码块叫做函数，不如&#8220;事件处理函数&#8221;，却很少说&#8220;事件处理方法&#8221;</p> <p>&nbsp;</p> <p>C#中没有行为这个概念  而事件，方法，函数则有<br /><br />事件，指的是一个类有可能会引发的一个调用，任何类都可以向一个有事件的类注册这个事件的监听，那么当事件引发时，类就会受到事件通知，从而响应。<br /><br />方法，指的是一个类的一些操作，比如一个Car类他有一个Move的移动方法，表示这个车子可以移动的操作（Operation）。<br /><br />函数，在C#里没有太严格的定义，我的理解是静态方法都可以称之为函数，因为函数一般不和类的实例相关，而静态方法具有这个特性。函数一般代表一个子操作，他会执行一些计算或者其他纯代码性的过程，比如Math类具有很多算数学的函数，比如计算三角的函数。</p> <p>&nbsp;</p> <p>方法和函数只是不同的语言环境下的不同说法，他们都是一样的。都可以返回值。习惯上面向对象语言中用方法一词，也有例外就是构造函数，构造函数不称为构造方法，只是习惯问题。而在面向过程的语言中一般没有方法的说法，都叫做函数。但他们实质上从语法规则上看，基本一样，也就是定义的规则相同，调用的规则相同，当然也都可以有返回值或者都可以无返回值。</p> <p>&nbsp;</p> <p>一个函数由这么几部分组成，函数名、参数个数、参数类型、返回值，就是把函数名字去掉以后剩下的东西（返回值、参数、调用方式等）。函数在重载时，利用函数签名的不同（即参数个数与类型的不同）来区别调用者到底调用的是那个方法。</p> <img src ="http://www.cnitblog.com/yide/aggbug/78152.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-18 20:39 <a href="http://www.cnitblog.com/yide/archive/2012/03/18/78152.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>cookie对象</title><link>http://www.cnitblog.com/yide/archive/2012/03/15/78103.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 15 Mar 2012 03:22:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/15/78103.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78103.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/15/78103.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78103.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78103.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">cookie 常用来对用户进行识别。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">实例：</span></div><div><span style="font-size: 12px;">Welcome cookie</span></div><div><span style="font-size: 12px;">如何创建欢迎 cookie。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim numvisits</span></div><div><span style="font-size: 12px;">response.cookies("NumVisits").Expires=date+365&nbsp;</span></div><div><span style="font-size: 12px;">numvisits=request.cookies("NumVisits")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">if numvisits="" then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.cookies("NumVisits")=1</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write("欢迎！这是您第一次访问本页面。")</span></div><div><span style="font-size: 12px;">else</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.cookies("NumVisits")=numvisits+1</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write("之前，您已经访问过本页面 ")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write(numvisits &amp; " 次。")</span></div><div><span style="font-size: 12px;">end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">什么是 Cookie?</span></div><div><span style="font-size: 12px;">cookie 常用来对用户进行识别。cookie 是一种服务器留在用户电脑中的小文件。每当同一台电脑通过浏览器请求页面时，这台电脑也会发送 cookie。通过 ASP，您能够创建并取回 cookie 的值。</span></div><div><span style="font-size: 12px;">如何创建 cookie?</span></div><div><span style="font-size: 12px;">"Response.Cookies" 命令用于创建 cookie。</span></div><div><span style="font-size: 12px;">注意：Response.Cookies 命令必须位于 &lt;html&gt; 标签之前。</span></div><div><span style="font-size: 12px;">在下面的例子中，我们会创建一个名为 "firstname" 的 cookie，并向其赋值 "Alex"：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Cookies("firstname")="Alex"</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">向 cookie 分配属性也是可以的，比如设置 cookie 的失效时间：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Cookies("firstname")="Alex"&nbsp;</span></div><div><span style="font-size: 12px;">Response.Cookies("firstname").Expires=#May 10,2020#</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">如何取回 cookie 的值？</span></div><div><span style="font-size: 12px;">"Request.Cookies" 命令用于取回 cookie 的值。</span></div><div><span style="font-size: 12px;">在下面的例子中，我们取回了名为 "firstname" 的 cookie 的值，并把值显示到了页面上：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">fname=Request.Cookies("firstname")</span></div><div><span style="font-size: 12px;">response.write("Firstname=" &amp; fname)</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">输出：</span></div><div><span style="font-size: 12px;">Firstname=Alex</span></div><div><span style="font-size: 12px;">带有键的 cookie</span></div><div><span style="font-size: 12px;">如果一个 cookie 包含多个值的一个集合，我们就可以说 cookie 拥有键（Keys）。</span></div><div><span style="font-size: 12px;">在下面的例子中，我们会创建一个名为 "user" 的 cookie 集。"user" cookie 拥有包含用户信息的键：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("firstname")="John"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("lastname")="Adams"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("country")="UK"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("age")="25"</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">读取所有的 cookie</span></div><div><span style="font-size: 12px;">请阅读下面的代码：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Cookies("firstname")="Alex"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("firstname")="John"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("lastname")="Adams"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("country")="UK"</span></div><div><span style="font-size: 12px;">Response.Cookies("user")("age")="25"</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">假设您的服务器将所有的这些 cookie 传给了某个用户。</span></div><div><span style="font-size: 12px;">现在，我们需要读取这些 cookie。下面的例子向您展示如何做到这一点（请注意，下面的代码会使用 HasKeys 检查 cookie 是否拥有键）：</span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim x,y</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp;for each x in Request.Cookies</span></div><div><span style="font-size: 12px;">&nbsp; response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; if Request.Cookies(x).HasKeys then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; for each y in Request.Cookies(x)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; response.write(x &amp; ":" &amp; y &amp; "=" &amp; Request.Cookies(x)(y))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; response.write("&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; next</span></div><div><span style="font-size: 12px;">&nbsp; else</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Response.Write(x &amp; "=" &amp; Request.Cookies(x) &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; end if</span></div><div><span style="font-size: 12px;">&nbsp; response.write "&lt;/p&gt;"</span></div><div><span style="font-size: 12px;">next</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;">输出：</span></div><div><span style="font-size: 12px;">firstname=Alex</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">user:firstname=John</span></div><div><span style="font-size: 12px;">user:lastname=Adams</span></div><div><span style="font-size: 12px;">user:country=UK</span></div><div><span style="font-size: 12px;">user:age=25</span></div><div><span style="font-size: 12px;">如何应对不支持 cookie 的浏览器？</span></div><div><span style="font-size: 12px;">如果您的应用程序需要和不支持 cookie 的浏览器打交道，那么您不得不使用其他的办法在您的应用程序中的页面之间传递信息。这里有两种办法：</span></div><div><span style="font-size: 12px;">1. 向 URL 添加参数</span></div><div><span style="font-size: 12px;">您可以向 URL 添加参数：</span></div><div><span style="font-size: 12px;">&lt;a href="welcome.asp?fname=John&amp;lname=Adams"&gt;</span></div><div><span style="font-size: 12px;">Go to Welcome Page</span></div><div><span style="font-size: 12px;">&lt;/a&gt;</span></div><div><span style="font-size: 12px;">然后在类似于下面这个 "welcome.asp" 文件中取回这些值：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">fname=Request.querystring("fname")</span></div><div><span style="font-size: 12px;">lname=Request.querystring("lname")</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;Hello " &amp; fname &amp; " " &amp; lname &amp; "!&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;Welcome to my Web site!&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">2. 使用表单</span></div><div><span style="font-size: 12px;">您还可以使用表单。当用户点击提交按钮时，表单会把用户输入的数据提交给 "welcome.asp" ：</span></div><div><span style="font-size: 12px;">&lt;form method="post" action="welcome.asp"&gt;</span></div><div><span style="font-size: 12px;">First Name: &nbsp;&lt;input type="text" name="fname" value=""&gt;</span></div><div><span style="font-size: 12px;">Last Name: &lt;input type="text" name="lname" value=""&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="Submit"&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">然后在 "welcome.asp" 文件中取回这些值，就像这样：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">fname=Request.form("fname")</span></div><div><span style="font-size: 12px;">lname=Request.form("lname")</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;Hello " &amp; fname &amp; " " &amp; lname &amp; "!&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;Welcome to my Web site!&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div style="font-family: Tahoma; font-size: 11px; "></div> <img src ="http://www.cnitblog.com/yide/aggbug/78103.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-15 11:22 <a href="http://www.cnitblog.com/yide/archive/2012/03/15/78103.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>session对象</title><link>http://www.cnitblog.com/yide/archive/2012/03/15/78102.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 15 Mar 2012 03:15:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/15/78102.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78102.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/15/78102.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78102.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78102.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session 对象用于存储关于某个用户会话（session）的信息，或者修改相关的设置。存储在 session 对象中的变量掌握着单一用户的信息，同时这些信息对于页面中的所有页面都是可用的。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session 对象</span></div><div><span style="font-size: 12px;">当您正在操作一个应用程序时，您会启动它，然后做些改变，随后关闭它。这个过程很像一次对话（Session）。计算机知道你是谁。它也知道你在何时启动和关闭这个应用程序。但是在因特网上，问题出现了：web 服务器不知道你是谁，也不知道你做什么，这是由于 HTTP 地址无法留存状态（信息）。</span></div><div><span style="font-size: 12px;">ASP 通过为每个用户创一个唯一的 cookie 解决了这个问题。cookie 发送到服务器，它包含了可识别用户的信息。这个接口称作 Session 对象。</span></div><div><span style="font-size: 12px;">Session 对象用于存储关于某个用户会话（session）的信息，或者修改相关的设置。存储在 session 对象中的变量掌握着单一用户的信息，同时这些信息对于页面中的所有页面都是可用的。存储于 session 变量中的信息通常是 name、id 以及参数等。服务器会为每位新用户创建一个新的 Session 对象，并在 session 到期后撤销这个对象。</span></div><div><span style="font-size: 12px;">下面是 Session 对象的集合、属性、方法以及事件：</span></div><div><span style="font-size: 12px;">集合</span></div><div><span style="font-size: 12px;">集合<span style="white-space:pre">	</span>描述</span></div><div><span style="font-size: 12px;">Contents<span style="white-space:pre">	</span>包含所有通过脚本命令追加到 session 的条目。</span></div><div><span style="font-size: 12px;">StaticObjects<span style="white-space:pre">	</span>包含了所有使用 HTML 的 &lt;object&gt; 标签追加到 session 的对象。</span></div><div><span style="font-size: 12px;">属性</span></div><div><span style="font-size: 12px;">属性<span style="white-space:pre">	</span>描述</span></div><div><span style="font-size: 12px;">CodePage<span style="white-space:pre">	</span>规定显示动态内容时使用的字符集</span></div><div><span style="font-size: 12px;">LCID<span style="white-space:pre">	</span>设置或返回指定位置或者地区的一个整数。诸如日期、时间以及货币的内容会根据位置或者地区来显示。</span></div><div><span style="font-size: 12px;">SessionID<span style="white-space:pre">	</span>为每个用户返回一个唯一的 id。此 id 由服务器生成。</span></div><div><span style="font-size: 12px;">Timeout<span style="white-space:pre">	</span>设置或返回应用程序中的 session 对象的超时时间（分钟）。</span></div><div><span style="font-size: 12px;">方法</span></div><div><span style="font-size: 12px;">方法<span style="white-space:pre">	</span>描述</span></div><div><span style="font-size: 12px;">Abandon<span style="white-space:pre">	</span>撤销一个用户的 session。</span></div><div><span style="font-size: 12px;">Contents.Remove<span style="white-space:pre">	</span>从 Contents 集合删除一个项目。</span></div><div><span style="font-size: 12px;">Contents.RemoveAll()<span style="white-space:pre">	</span>从 Contents 集合删除全部项目。</span></div><div><span style="font-size: 12px;">事件</span></div><div><span style="font-size: 12px;">事件<span style="white-space:pre">	</span>描述</span></div><div><span style="font-size: 12px;">Session_OnEnd<span style="white-space:pre">	</span>当一个会话结束时此事件发生。</span></div><div><span style="font-size: 12px;">Session_OnStart<span style="white-space:pre">	</span>当一个会话开始时此事件发生。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1.设置并返回 LCID</span></div><div><span style="font-size: 12px;">本例演示 "LCID" 属性。此属性设置并返回一个指示位置或者地区的整数。类似于日期、时间以及货币等内容都要根据位置或者地区来显示。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;% &nbsp;</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("本页的默认 LCID 是：" &amp; Session.LCID &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的日期格式是：" &amp; date() &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的货币格式是：" &amp; FormatCurrency(350))</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session.LCID=1036</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("现在 LCID 变更为：" &amp; Session.LCID &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的日期格式是：" &amp; date() &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的货币格式是：" &amp; FormatCurrency(350))</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session.LCID = 3079</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("现在 LCID 变更为：" &amp; Session.LCID &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的日期格式是：" &amp; date() &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的货币格式是：" &amp; FormatCurrency(350))</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session.LCID = 2057</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("现在 LCID 变更为：" &amp; Session.LCID &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的日期格式是：" &amp; date() &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">response.write("上面的 LCID 的货币格式是：" &amp; FormatCurrency(350))</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2.返回 SessionID</span></div><div><span style="font-size: 12px;">本例演示 "SessionID" 属性。该属性为每位用户返回一个唯一的 id。这个 id 由服务器生成。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Write(Session.SessionID)</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3.session 的超时</span></div><div><span style="font-size: 12px;">本例演示 "Timeout" 属性。这个例子设置并返回 session 的超时时间（分钟）。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;% &nbsp;</span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("默认 Timeout 是：" &amp; Session.Timeout &amp; " 分钟。")</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session.Timeout=30</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">response.write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">response.write("现在的 Timeout 是 " &amp; Session.Timeout &amp; " 分钟。")</span></div><div><span style="font-size: 12px;">response.write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Session 何时开始？</span></div><div><span style="font-size: 12px;">Session 开始于：</span></div><div><span style="font-size: 12px;">当某个新用户请求了一个 ASP 文件，并且 Global.asa 文件引用了 Session_OnStart 子程序时；</span></div><div><span style="font-size: 12px;">当某个值存储在 Session 变量中时；</span></div><div><span style="font-size: 12px;">当某个用户请求了一个 ASP 文件，并且 Global.asa 使用 &lt;object&gt; 标签通过 session 的 scope 来例示某个对象时；</span></div><div><span style="font-size: 12px;">Session 何时结束?</span></div><div><span style="font-size: 12px;">假如用户没有在规定的时间内在应用程序中请求或者刷新页面，session 就会结束。默认值为 20 分钟。</span></div><div><span style="font-size: 12px;">如果您希望将超时的时间间隔设置得更长或更短，可以设置 Timeout 属性。</span></div><div><span style="font-size: 12px;">下面的例子设置了 5 分钟的超时时间间隔：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Session.Timeout=5</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">要立即结束 session，可使用 Abandon 方法：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Session.Abandon</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">注意：使用 session 时主要的问题是它们该在何时结束。我们不会知道用户最近的请求是否是最后的请求。因此我们不清楚该让 session&#8220; 存活&#8221;多久。为某个空闲的 session 等待太久会耗尽服务器的资源。然而假如 session 被过早地删除，那么用户就不得不一遍又一遍地重新开始，这是因为服务器已经删除了所有的信息。寻找合适的超时间隔时间是很困难的。</span></div><div><span style="font-size: 12px;">提示：如果您正在使用 session 变量，请不要在其中存储大量的数据。</span></div><div><span style="font-size: 12px;">存储和取回 session 变量</span></div><div><span style="font-size: 12px;">Session 对象最大的优点是可在其中存储变量，以供后续的网页读取，其应用范围是很广的。</span></div><div><span style="font-size: 12px;">下面的例子把 "Donald Duck" 赋值给名为 username 的 session 变量，并把 "50" 赋值给名为 age 的 session 变量：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Session("username")="Donald Duck"</span></div><div><span style="font-size: 12px;">Session("age")=50</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">一旦值被存入 session 变量，它就能被 ASP 应用程序中的任何页面使用：</span></div><div><span style="font-size: 12px;">Welcome &lt;%Response.Write(Session("username"))%&gt;</span></div><div><span style="font-size: 12px;">上面这行程序返回的结果是: "Welcome Donald Duck"。</span></div><div><span style="font-size: 12px;">也可以在 session 对象中保存用户参数，然后通过访问这些参数来决定向用户返回什么页面。</span></div><div><span style="font-size: 12px;">下面的例子规定，假如用户使用低显示器分辨率，则返回纯文本版本的页面：</span></div><div><span style="font-size: 12px;">&lt;%If Session("screenres")="low" Then%&gt;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; This is the text version of the page</span></div><div><span style="font-size: 12px;">&lt;%Else%&gt;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; This is the multimedia version of the page</span></div><div><span style="font-size: 12px;">&lt;%End If%&gt;</span></div><div><span style="font-size: 12px;">移除 session 变量</span></div><div><span style="font-size: 12px;">contents 集合包含所有的 session 变量。</span></div><div><span style="font-size: 12px;">可通过 remove 方法来移除 session 变量。</span></div><div><span style="font-size: 12px;">在下面的例子中，假如 session 变量 "age" 的值小于 18，则移除 session 变量 "sale"：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">If Session.Contents("age")&lt;18 then&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; Session.Contents.Remove("sale")</span></div><div><span style="font-size: 12px;">End If&nbsp;</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">如需移除 session 中的所有变量，请使用 RemoveAll 方法：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Session.Contents.RemoveAll()</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">遍历 contents 集合</span></div><div><span style="font-size: 12px;">contents 集合包含所有的 session 变量。可通过遍历 contents 集合，来查看其中存储的变量：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Session("username")="Donald Duck"</span></div><div><span style="font-size: 12px;">Session("age")=50</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">dim i</span></div><div><span style="font-size: 12px;">For Each i in Session.Contents</span></div><div><span style="font-size: 12px;">&nbsp; Response.Write(i &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">Next</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">结果：</span></div><div><span style="font-size: 12px;">username</span></div><div><span style="font-size: 12px;">age</span></div><div><span style="font-size: 12px;">如果需要了解 contents 集合中的项目数量，可使用 count 属性：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim i</span></div><div><span style="font-size: 12px;">dim j</span></div><div><span style="font-size: 12px;">j=Session.Contents.Count</span></div><div><span style="font-size: 12px;">Response.Write("Session variables: " &amp; j)</span></div><div><span style="font-size: 12px;">For i=1 to j</span></div><div><span style="font-size: 12px;">&nbsp; Response.Write(Session.Contents(i) &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">Next</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">结果：</span></div><div><span style="font-size: 12px;">Session variables: 2</span></div><div><span style="font-size: 12px;">Donald Duck</span></div><div><span style="font-size: 12px;">50</span></div><div><span style="font-size: 12px;">遍历 StaticObjects 集合</span></div><div><span style="font-size: 12px;">可通过循环 StaticObjects 集合，来查看存储在 session 对象中所有对象的值：</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim i</span></div><div><span style="font-size: 12px;">For Each i in Session.StaticObjects</span></div><div><span style="font-size: 12px;">&nbsp; Response.Write(i &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">Next</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div style="font-family: Tahoma; font-size: 11px; "></div> <img src ="http://www.cnitblog.com/yide/aggbug/78102.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-15 11:15 <a href="http://www.cnitblog.com/yide/archive/2012/03/15/78102.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Request对象</title><link>http://www.cnitblog.com/yide/archive/2012/03/15/78101.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 15 Mar 2012 03:02:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/15/78101.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78101.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/15/78101.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78101.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78101.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Request 对象</span></div><div><span style="font-size: 12px;">当浏览器向服务器请求页面时，这个行为就被称为一个 request（请求）。</span></div><div><span style="font-size: 12px;">ASP Request 对象用于从用户那里获取信息。它的集合、属性和方法描述如下：</span></div><div><span style="font-size: 12px;">集合</span></div><div><span style="font-size: 12px;">集合<span style="white-space:pre">	</span>描述</span></div><div><span style="font-size: 12px;">ClientCertificate<span style="white-space:pre">	</span>包含了存储于客户证书中的域值（field values）</span></div><div><span style="font-size: 12px;">Cookies<span style="white-space:pre">	</span>包含了 HTTP 请求中发送的所有 cookie 值</span></div><div><span style="font-size: 12px;">Form<span style="white-space:pre">	</span>包含了使用 post 方法由表单发送的所有的表单（输入）值</span></div><div><span style="font-size: 12px;">QueryString<span style="white-space:pre">	</span>包含了 HTTP 查询字符串中所有的变量值</span></div><div><span style="font-size: 12px;">ServerVariables<span style="white-space:pre">	</span>包含了所有的服务器变量值</span></div><div><span style="font-size: 12px;">属性</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">QueryString 集合 实例</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1.当用户点击链接时发送查询信息</span></div><div><span style="font-size: 12px;">本例演示如何在链接中向页面发送一些额外的查询信息，并在目标页面中取回这些信息（在本例中是同一页面）。</span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;a href="/example/aspe/demo_aspe_simplequerystring.asp?color=green"&gt;Example&lt;/a&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Write(Request.QueryString)</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2.对 QueryString 集合的简单应用</span></div><div><span style="font-size: 12px;">本例演示 QueryString 集合如何从表单取回值。此表单使用 GET 方法，</span></div><div><span style="font-size: 12px;">这意外着所发送的信息对用户来说是可见的（在地址中）。</span></div><div><span style="font-size: 12px;">GET 方法还会限制所发送信息的数量。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_simplereqquery.asp" method="get"&gt;</span></div><div><span style="font-size: 12px;">First name: &lt;input type="text" name="fname"&gt;&lt;br /&gt;</span></div><div><span style="font-size: 12px;">Last name: &lt;input type="text" name="lname"&gt;&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="Submit"&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Write(Request.QueryString)</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3.如何使用从表单传来的信息</span></div><div><span style="font-size: 12px;">本例演示如何使用从表单取回的值。我们会使用 QueryString 集合。此表单使用 GET 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_reqquery.asp" method="get"&gt;</span></div><div><span style="font-size: 12px;">您的姓名：&lt;input type="text" name="fname" size="20" /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="提交" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim fname</span></div><div><span style="font-size: 12px;">fname=Request.QueryString("fname")</span></div><div><span style="font-size: 12px;">If fname&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("你好！" &amp; fname &amp; "！&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("今天过得怎么样？")</span></div><div><span style="font-size: 12px;">End If</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">4.来自表单的更多信息</span></div><div><span style="font-size: 12px;">本例演示假如输入字段包含若干相同的名称的话，QueryString 会包含什么内容。它将展示如何把这些相同的名称分隔开来。它也会展示如何使用 count 关键词来对 "name" 属性进行计数。此表单使用 GET 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">If Request.QueryString&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; If Request.QueryString("name")&lt;&gt;", " Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name1=Request.QueryString("name")(1)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;name2=Request.QueryString("name")(2)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; end if</span></div><div><span style="font-size: 12px;">end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_reqquery2.asp" method="get"&gt;</span></div><div><span style="font-size: 12px;">First name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="name" value="&lt;%=name1%&gt;" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">Last name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="name" value="&lt;%=name2%&gt;" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="Submit" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;hr&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">If Request.QueryString&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("The information received from the form was:")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("name=" &amp; Request.QueryString("name"))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("The name property's count is: ")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write(Request.QueryString("name").Count)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("First name=" &amp; name1)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("Last name=" &amp; name2)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Form 集合 实例</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1.一个 Form 集合的简单应用</span></div><div><span style="font-size: 12px;">本例演示 Form 集合如何从表单取回值。此表单使用 POST 方法，这意味着发送的信息对用户来说是不可见的，并且对所发送信息的量没有限制（可发送大量的信息）。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_simpleform1.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">First name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="fname" value="Donald" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">Last name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="lname" value="Duck" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="Submit" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">Response.Write(Request.Form)</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2.如何使用来自表单的信息</span></div><div><span style="font-size: 12px;">本例演示如何使用从表单取回的信息。我们使用了 Form 集合。表单使用了 POST 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_simpleform.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">您的姓名：&lt;input type="text" name="fname" size="20" /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="提交" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim fname</span></div><div><span style="font-size: 12px;">fname=Request.Form("fname")</span></div><div><span style="font-size: 12px;">If fname&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("您好！" &amp; fname &amp; "！&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("今天过得怎么样？")</span></div><div><span style="font-size: 12px;">End If</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3.来自表单的更多信息</span></div><div><span style="font-size: 12px;">本例演示假如若干的输入域使用了相同的名称，Form 集合会包含什么信息。它将展示如何把这些相同的名称分割开来。它也会展示如何使用 count 关键词来对 "name" 属性进行计数。此表单使用 POST 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_form2.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">First name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="name" value="Donald" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">Last name:</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="name" value="Duck" /&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="Submit" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;hr /&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;p&gt;来自上面的表单的信息：&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">If Request.Form("name")&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("name=" &amp; Request.Form("name"))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("name 属性的数目：")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write(Request.Form("name").Count)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("First name=" &amp; Request.Form("name")(1))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;&lt;p&gt;")&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("Last name=" &amp; Request.Form("name")(2))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write("&lt;/p&gt;")&nbsp;</span></div><div><span style="font-size: 12px;">End if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">4.带有单选按钮的表单</span></div><div><span style="font-size: 12px;">本例演示如何使用 Form 集合通过单选按钮与用户进行交互。此表单使用 POST 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim cars</span></div><div><span style="font-size: 12px;">cars=Request.Form("cars")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_radiob.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;请选择您喜欢的汽车：&lt;/p&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;input type="radio" name="cars"</span></div><div><span style="font-size: 12px;">&lt;%if cars="Volvo" then Response.Write("checked")%&gt;</span></div><div><span style="font-size: 12px;">value="Volvo"&gt;Volvo&lt;/input&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="radio" name="cars"</span></div><div><span style="font-size: 12px;">&lt;%if cars="Saab" then Response.Write("checked")%&gt;</span></div><div><span style="font-size: 12px;">value="Saab"&gt;Saab&lt;/input&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="radio" name="cars"</span></div><div><span style="font-size: 12px;">&lt;%if cars="BMW" then Response.Write("checked")%&gt;</span></div><div><span style="font-size: 12px;">value="BMW"&gt;BMW&lt;/input&gt;</span></div><div><span style="font-size: 12px;">&lt;br /&gt;&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="提交" /&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">if cars&lt;&gt;"" then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write("&lt;p&gt;您喜欢的汽车是" &amp; cars &amp; "&lt;/p&gt;")</span></div><div><span style="font-size: 12px;">end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">5.带有复选按钮的表单</span></div><div><span style="font-size: 12px;">本例演示如何使用 Form 集合通过复选按钮与用户进行交互。此表单使用 POST 方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">fruits=Request.Form("fruits")</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_checkboxes.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;您喜欢哪些水果：&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="checkbox" name="fruits" value="Apples"</span></div><div><span style="font-size: 12px;">&lt;%if instr(fruits,"Apple") then Response.Write("checked")%&gt;&gt;</span></div><div><span style="font-size: 12px;">Apple</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="checkbox" name="fruits" value="Oranges"</span></div><div><span style="font-size: 12px;">&lt;%if instr(fruits,"Oranges") then Response.Write("checked")%&gt;&gt;</span></div><div><span style="font-size: 12px;">Orange</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="checkbox" name="fruits" value="Bananas"</span></div><div><span style="font-size: 12px;">&lt;%if instr(fruits,"Banana") then Response.Write("checked")%&gt;&gt;</span></div><div><span style="font-size: 12px;">Banana</span></div><div><span style="font-size: 12px;">&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="提交"&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">if fruits&lt;&gt;"" then%&gt;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;&lt;p&gt;您喜欢：&lt;%Response.Write(fruits)%&gt;&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;%end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">1.获取用户信息</span></div><div><span style="font-size: 12px;">如何查明访问者的浏览器类型、IP 地址等信息。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;您正在通过这款浏览器访问我们的站点：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("http_user_agent"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;您的 IP 地址是：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("remote_addr"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;IP 地址的 DNS 查询是：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("remote_host"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;调用该页面所用的方法是：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("request_method"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;服务器的域名：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("server_name"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;服务器的端口：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("server_port"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">&lt;b&gt;服务器的软件：&lt;/b&gt;</span></div><div><span style="font-size: 12px;">&lt;%Response.Write(Request.ServerVariables("server_software"))%&gt;</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">2.获取服务器变量</span></div><div><span style="font-size: 12px;">本例演示如何使用 ServerVariables 集合取得访问者的浏览器类型、IP 地址等信息。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;p&gt;</span></div><div><span style="font-size: 12px;">所有可能的服务器变量：</span></div><div><span style="font-size: 12px;">&lt;/p&gt;</span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">For Each Item in Request.ServerVariables</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; Response.Write(Item &amp; "&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">Next</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">3.创建 welcome cookie</span></div><div><span style="font-size: 12px;">本例演示如何使用 Cookies 集合创建一个欢迎 cookie。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">dim numvisits</span></div><div><span style="font-size: 12px;">response.cookies("NumVisits").Expires=date+365&nbsp;</span></div><div><span style="font-size: 12px;">numvisits=request.cookies("NumVisits")</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">if numvisits="" then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.cookies("NumVisits")=1</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write("欢迎！这是您第一次访问本页面。")</span></div><div><span style="font-size: 12px;">else</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.cookies("NumVisits")=numvisits+1</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write("之前，您已经访问过本页面 ")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;response.write(numvisits &amp; " 次。")</span></div><div><span style="font-size: 12px;">end if</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">4.探测用户发送的字节总数</span></div><div><span style="font-size: 12px;">本例演示如何使用 TotalBytes 属性来取得用户在 Request 对象中发送的字节总数。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;html&gt;</span></div><div><span style="font-size: 12px;">&lt;body&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;form action="/example/aspe/demo_aspe_totalbytes.asp" method="post"&gt;</span></div><div><span style="font-size: 12px;">请键入一些字符：</span></div><div><span style="font-size: 12px;">&lt;input type="text" name="txt"&gt;&lt;br /&gt;&lt;br /&gt;</span></div><div><span style="font-size: 12px;">&lt;input type="submit" value="提交"&gt;</span></div><div><span style="font-size: 12px;">&lt;/form&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;%</span></div><div><span style="font-size: 12px;">If Request.Form("txt")&lt;&gt;"" Then</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write("您提交了：")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write(Request.Form)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write("&lt;br /&gt;&lt;br /&gt;")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write("字节总计：")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Response.Write(Request.Totalbytes)</span></div><div><span style="font-size: 12px;">End If</span></div><div><span style="font-size: 12px;">%&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&lt;/body&gt;</span></div><div><span style="font-size: 12px;">&lt;/html&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div style="font-family: Tahoma; font-size: 11px; "></div> <img src ="http://www.cnitblog.com/yide/aggbug/78101.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-15 11:02 <a href="http://www.cnitblog.com/yide/archive/2012/03/15/78101.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>.net Request对象</title><link>http://www.cnitblog.com/yide/archive/2012/03/15/78099.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 15 Mar 2012 01:57:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/15/78099.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78099.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/15/78099.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78099.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78099.html</trackback:ping><description><![CDATA[<pre id="content-863785586"  mb10"="" style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; word-wrap: break-word; zoom: 1; background-color: #fdfff8; "> </pre><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Asp内建的request对象拥有五个获取客户端资料的方法(QueryString/Form/Cookies/ServerVariables/ClientCertificate)。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;语法：request.方法名称("参数")|request("参数")&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;如果采用后者，系统会自动选择相应的方法。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;Form&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; 这里再重新强调Form的一些属性:&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Enctype=资料传送的MIME形态&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Method=传送资料的方式Get/Post&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Onrest=按下rest键调用的程序&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Onsubmit=按下sumit键调用程序&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; Target=输出内容的frame窗口&gt;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; 使用Form传送信息一般有三种方式：由html网页内的Form传信息给其他Asp；由Asp内的Form传信息给另外一个Asp；Asp内的信息传送给自身。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;语法:Request.Form(参数)[(索引)]&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;其中参数表示Form中元素的名称，索引表示相同名称元素的顺序号。&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;例:&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; 可循环读取名称为user的元素，其中Count是Form的系统属性，用于计算同名元素的个数，如果该元素不存在，则其值为零。如果没有指明要读取第几个同名元素，则系统会把全部同名元素的值都读取出来，并用&#8220;，&#8221;作间隔。&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; 例：Request.form("user")=abc，bcd,cde</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;2、QueryString&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;语法:Request.QueryString(参数)[(索引)]&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;除了用Form传输资料外，还可通过在超链接后接&#8220;?&#8221;的方式传输信息，如:，这时可通过Request.QueryString("user")读取传输的信息；如果出现多个重名的参数，如:，则第一次</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; Resquest.QueryString("user")=abc，第二次</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; Resquest.QueryString("user")=bcd，第三次</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; Resquest.QueryString("user")=cde。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 3、ServerVariables&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;语法:ServerVariables(参数名称)&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;我们知道Web/Browse的传输协议是http，http的报头会有一些客户端的信息，如&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; 客户IP地址、浏览器的语言系统等。这时可通过Request.ServerVariables("***")获取相关信息，如Request.ServerVariables("Accept_Language")可获取客户端浏览器 的语系。其他系统参数见下表：&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; SERVER_NAME server的机器名称或IP地址。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;SERVER_PORT server正在运行的端口号&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;REQUEST_METHOD 发出request的方法(GET/POST/HEAD&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;SCRIPT_NAME 程序被调用的路径，如：CGI-bin/a.pl。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;REMOTE_HOST 发出request请求的远端机器(client)的名称。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;REMOTE_ADDR 发出request请求的远端机器(client)的IP地址。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;REMOTE_IDENT 发出request的使用者名称(如是拨号上网，则为用户ID)，当NCSA IdentityCheck为enabled，而且client机器支持RFC 931时，该变量有效。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;CONTENT_TYPE 数据的MIME类型，如：&#8220;text/html&#8221;。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;HTTP_ACCEPT client可以接受的MIME类型列表。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;HTTP_USER_AGENT client发出request的浏览器类型。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp;HTTP_REFERER 在读取CGI程序之前，client所指的文本URL。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 4、Cookies&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 在客户端，Cookies记录了客户端浏览器很多的信息，我们可通过Request.Cookies("名称")命令获取它的值，也可通过Response.Cookies("名称")="值"在客户端记录一些信息，以便控制访问者。设置多重Cookies的方法为Response.Cookies("名称")("名称")="值"。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 5、Cache&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 我们可以在浏览器上设置从Cache中抽取已经访问过的页面的信息，同样，在Asp程序中也可进行类似的设置。其中Response.Clear为清空客户端的内存。Response.Buffer=True设置可从Cache中读取资料(缺省时为False)。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; 6、ClientCertificate&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp;ClientCertificate用于获取客户端浏览器的身份确认信息（符合X.509标准），但客户端浏览器必须支持SSL3.0或PCT1协议。这里需做两步工作，第一步：web server必须启动用户端认证选项；第二步：对客户端浏览器进行相应设置，这样，该方法才会生效，否则，传回empty值。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div style="font-family: Tahoma; font-size: 11px; "></div><img src ="http://www.cnitblog.com/yide/aggbug/78099.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-15 09:57 <a href="http://www.cnitblog.com/yide/archive/2012/03/15/78099.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>子页面调用父页面函数</title><link>http://www.cnitblog.com/yide/archive/2012/03/13/78084.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 13 Mar 2012 14:27:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/13/78084.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78084.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/13/78084.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78084.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78084.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 如果用 javaScript 的话， 子页面用 opener 就可以引用父页面的 window， 如：opener.document.all.txt_client_Id.value &nbsp;//获取值opener.document.all.btn_client_Id.click() // 触发事件父页面：要调用父页面的click事件Protected Sub LinkButton1_Click...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yide/archive/2012/03/13/78084.html'>阅读全文</a><img src ="http://www.cnitblog.com/yide/aggbug/78084.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-13 22:27 <a href="http://www.cnitblog.com/yide/archive/2012/03/13/78084.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ArrayList--Gridview--datasource</title><link>http://www.cnitblog.com/yide/archive/2012/03/13/78082.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 13 Mar 2012 13:37:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/13/78082.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78082.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/13/78082.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78082.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78082.html</trackback:ping><description><![CDATA[<div></div><div id="article_content"><div bg_csharp"=""> <ol> <li>//定义一些实体  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;Entity&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;Entity(string&nbsp;Names,string&nbsp;Sex)&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.Names&nbsp;=&nbsp;Names;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.Sex&nbsp;=&nbsp;Sex;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;string&nbsp;Names&nbsp;{&nbsp;get;&nbsp;set;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;string&nbsp;Sex&nbsp;{&nbsp;get;&nbsp;set;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//定义一些String  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;class&nbsp;SomeStr&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;string&nbsp;Names;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;string&nbsp;Sex;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;SomeStr(string&nbsp;Names,string&nbsp;Sex)&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.Names&nbsp;=&nbsp;Names;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.Sex&nbsp;=&nbsp;Sex;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ArrayList实体绑定GridView  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;AL()&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;ai&nbsp;=&nbsp;new&nbsp;ArrayList();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ai.Add(new&nbsp;Entity("Dean",&nbsp;"Male"));&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ai.Add(new&nbsp;Entity("Cass",&nbsp;"Male"));&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GridView1.DataSource&nbsp;=&nbsp;ai;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GridView1.DataBind();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//ArrayList字符绑定GridView  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;void&nbsp;AlStr()&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ArrayList&nbsp;ai&nbsp;=&nbsp;new&nbsp;ArrayList();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ai.Add(new&nbsp;SomeStr("Dean",&nbsp;"Male"));&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataTable&nbsp;dt&nbsp;=&nbsp;new&nbsp;DataTable();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//手动添加列名  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add("Names",&nbsp;System.Type.GetType("System.String"));&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Columns.Add("Sex",&nbsp;System.Type.GetType("System.String"));&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//从ArrayList读出每一个枚举  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IEnumerator&nbsp;ie&nbsp;=&nbsp;ai.GetEnumerator();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;(ie.MoveNext())&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//转换一下类型  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SomeStr&nbsp;sr&nbsp;=&nbsp;(SomeStr)ie.Current;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;DataRow&nbsp;dr&nbsp;=&nbsp;dt.NewRow();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//给列赋值  &nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr["Names"]&nbsp;=&nbsp;sr.Names;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dr["Sex"]&nbsp;=&nbsp;sr.Sex;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dt.Rows.Add(dr);&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GridView1.DataSource&nbsp;=&nbsp;dt;&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GridView1.DataBind();&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;</li> <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;</li></ol></div></div><img src ="http://www.cnitblog.com/yide/aggbug/78082.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-13 21:37 <a href="http://www.cnitblog.com/yide/archive/2012/03/13/78082.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>window.showModalDialog获取弹出页面返回值的2种方法</title><link>http://www.cnitblog.com/yide/archive/2012/03/13/78074.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 13 Mar 2012 08:23:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/13/78074.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78074.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/13/78074.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78074.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78074.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">一、window.showModalDialog获取弹出页面返回值的2种方法</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">----main.html---------主页面</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&lt;form name="form1"&gt;&nbsp;&nbsp;&nbsp;</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&lt;input type="text" name="fag1"&gt;&nbsp;&nbsp;&nbsp;</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&lt;input type="text" name="fag2"&gt;&nbsp;&nbsp;&nbsp;</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&lt;/form&gt;&nbsp;&nbsp;&nbsp;</span><br style="font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br /><br />..................................<br /><br />详见网址：<span style="background-color: #ffffff;"><a href="http://dalaoyer.com/article.php?id=378" title="http://dalaoyer.com/article.php?id=378">http://dalaoyer.com/article.php?id=378</a></span><img src ="http://www.cnitblog.com/yide/aggbug/78074.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-13 16:23 <a href="http://www.cnitblog.com/yide/archive/2012/03/13/78074.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>window.showModalDialog用法</title><link>http://www.cnitblog.com/yide/archive/2012/03/13/78073.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 13 Mar 2012 08:18:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/13/78073.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78073.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/13/78073.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78073.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78073.html</trackback:ping><description><![CDATA[<span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">基本介绍：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showModalDialog()&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;(IE&nbsp;4+&nbsp;支持)</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;showModelessDialog()&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;(IE&nbsp;5+&nbsp;支持)</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.showModalDialog()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;方法用来创建一个显示HTML内容的模态对话框。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.showModelessDialog()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;方法用来创建一个显示HTML内容的非模态对话框。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">使用方法：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vReturnValue&nbsp;=&nbsp;window.showModalDialog(sURL&nbsp;[,&nbsp;vArguments]&nbsp;[,sFeatures])</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vReturnValue&nbsp;=&nbsp;window.showModelessDialog(sURL&nbsp;[,&nbsp;vArguments]&nbsp;[,sFeatures])</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">参数说明：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sURL&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&nbsp;必选参数，类型：字符串。用来指定对话框要显示的文档的URL。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vArguments&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&nbsp;&nbsp;可选参数，类型：变体。用来向对话框传递参数。传递的参数类型不限，包括数组等。对话框通过window.dialogArguments来取得传递进来的参数。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sFeatures&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--&nbsp;&nbsp;&nbsp;&nbsp;可选参数，类型：字符串。用来描述对话框的外观等信息，可以使用以下的一个或几个，用分号&#8220;;&#8221;隔开。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">----------------</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">1.&nbsp;&nbsp;&nbsp;dialogHeight:&nbsp;&nbsp;&nbsp;对话框高度，不小于100px</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">2.&nbsp;&nbsp;&nbsp;dialogWidth:&nbsp;&nbsp;&nbsp;对话框宽度。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">3.&nbsp;&nbsp;&nbsp;dialogLeft:&nbsp;&nbsp;&nbsp;&nbsp;离屏幕左的距离。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">4.&nbsp;&nbsp;&nbsp;dialogTop:&nbsp;&nbsp;&nbsp;&nbsp;离屏幕上的距离。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">5.&nbsp;&nbsp;&nbsp;center:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;}&nbsp;：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否居中，默认yes，但仍可以指定高度和宽度。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">6.&nbsp;&nbsp;&nbsp;help:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;}：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否显示帮助按钮，默认yes。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">7.&nbsp;&nbsp;&nbsp;resizable:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;}&nbsp;[IE5+]：&nbsp;&nbsp;&nbsp;&nbsp;是否可被改变大小。默认no。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">8.&nbsp;&nbsp;&nbsp;status:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;}&nbsp;[IE5+]：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;是否显示状态栏。默认为yes[&nbsp;Modeless]或no[Modal]。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">9.&nbsp;&nbsp;&nbsp;scroll:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;|&nbsp;on&nbsp;|&nbsp;off&nbsp;}：是否显示滚动条。默认为yes。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">下面几个属性是用在HTA中的，在一般的网页中一般不使用。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">10.&nbsp;&nbsp;&nbsp;dialogHide:{&nbsp;yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;|&nbsp;on&nbsp;|&nbsp;off&nbsp;}：在打印或者打印预览时对话框是否隐藏。默认为no。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">11.&nbsp;&nbsp;&nbsp;edge:{&nbsp;sunken&nbsp;|&nbsp;raised&nbsp;}：指明对话框的边框样式。默认为raised。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">12.&nbsp;&nbsp;&nbsp;unadorned:{&nbsp;yes&nbsp;|&nbsp;no&nbsp;|&nbsp;1&nbsp;|&nbsp;0&nbsp;|&nbsp;on&nbsp;|&nbsp;off&nbsp;}：默认为no。</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">参数传递：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">1.&nbsp;&nbsp;&nbsp;要想对话框传递参数，是通过vArguments来进行传递的。类型不限制，对于字符串类型，最大为4096个字符。也可以传递对象，例如：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">-------------------------------</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">parent.htm</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;obj&nbsp;=&nbsp;new&nbsp;Object();</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;obj.name="51js";</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.showModalDialog("modal.htm",obj,"dialogWidth=200px;dialogHeight=100px");</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;/script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">modal.htm</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;obj&nbsp;=&nbsp;window.dialogArguments</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("您传递的参数为："&nbsp;+&nbsp;obj.name)</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;/script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">-------------------------------</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">2.&nbsp;&nbsp;&nbsp;可以通过window.returnValue向打开对话框的窗口返回信息，当然也可以是对象。例如：</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">------------------------------</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">parent.htm</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;=window.showModalDialog("modal.htm",,"dialogWidth=200px;dialogHeight=100px");</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(str);</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;/script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">modal.htm</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;script&gt;</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;window.returnValue="http://homepage.yesky.com";</span><br style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; " /><span style="font-family: Arial, 宋体; font-size: 14px; line-height: 24px; text-align: left; background-color: #f5f8fd; ">&lt;/script&gt;</span>&nbsp;<img src ="http://www.cnitblog.com/yide/aggbug/78073.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-13 16:18 <a href="http://www.cnitblog.com/yide/archive/2012/03/13/78073.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>window.opener 的用法</title><link>http://www.cnitblog.com/yide/archive/2012/03/13/78072.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 13 Mar 2012 07:09:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/13/78072.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78072.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/13/78072.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78072.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78072.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: window.opener 的用法&nbsp;window.opener 返回的是创建当前窗口的那个窗口的引用，比如点击了a.htm上的一个链接而打开了b.htm，然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为&#8220;name&#8221;的textbox中，就可以写为：&nbsp;window.opener.document.getElementById("name"...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yide/archive/2012/03/13/78072.html'>阅读全文</a><img src ="http://www.cnitblog.com/yide/aggbug/78072.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-13 15:09 <a href="http://www.cnitblog.com/yide/archive/2012/03/13/78072.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#与Javascript互相调用二</title><link>http://www.cnitblog.com/yide/archive/2012/03/12/78059.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Mon, 12 Mar 2012 13:17:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/12/78059.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78059.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/12/78059.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78059.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78059.html</trackback:ping><description><![CDATA[<div style="text-align: center; margin: 12pt 0cm 3pt"><strong><span style="font-size: large">C#与Javascript变量、函数之间的相互调用&nbsp; </span></strong></div>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: 10pt"><strong><span style="font-size: small">一、javascript调用C#代码解决方案<br /></span></strong></span><span style="font-size: small">// 第一种情况：<br /></span><span style="font-size: small">1.后台方法：<br /></span><span style="font-size: 10pt"></p>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">protected</span><span>&nbsp;</span><span class="keyword">string</span><span>&nbsp;CsharpVoid(</span><span class="keyword">string</span><span>&nbsp;strCC)&nbsp;&nbsp;</span></li><li><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>&nbsp;strCC;&nbsp;&nbsp;</span></span></li><li><span>}&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">protected string CsharpVoid(string strCC)
{
    return strCC;
}</textarea><span style="font-size: small"> <br /></span></span><span style="font-size: 10pt"><span style="font-size: small">2.javascript 调用<br /></span>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span>&lt;script&nbsp;language=</span><span class="string">"javascript"</span><span>&gt;&nbsp;&nbsp;</span></li><li><span>&lt;!--&nbsp;&nbsp;</span></li><li class="alt"><span>var&nbsp;s&nbsp;=&nbsp;</span><span class="string">"&lt;%=CsharpVoid("</span><span>www.&nbsp;baidu.com</span><span class="string">")%&gt;"</span><span>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></li><li><span>document.write(s);&nbsp;&nbsp;</span></li><li class="alt"><span></span><span class="comment">//&nbsp;--&gt; </span><span>&nbsp;&nbsp;</span></span></li><li><span>&lt;/script&gt;&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;script language="javascript"&gt;
&lt;!--
var s = "&lt;%=CsharpVoid("www. baidu.com")%&gt;";   
document.write(s);
// --&gt;
&lt;/script&gt;</textarea><span style="font-size: small">&nbsp;<br /></span></span><span style="font-size: small">// 第二种情况：<br /></span><span style="font-size: 10pt"><span style="font-size: small">1.后代码：<br /></span>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">protected</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;CsharpVoid()&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">string</span><span>&nbsp;strCC&nbsp;=&nbsp;</span><span class="string">"www.baidu.com"</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;Response.Write(strCC);&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;}&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">protected void CsharpVoid()
  {
    string strCC = "www.baidu.com";
    Response.Write(strCC);
  }</textarea><span style="font-size: small"><br /></span></span><span style="font-size: small">2.调用方法：CsharpVoid()<br /></span><span style="font-size: 10pt">
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">script</span><span>&nbsp;</span><span class="attribute">language</span><span>=</span><span class="attribute-value">"javascript"</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></li><li><span>&lt;!--&nbsp;&nbsp;</span></li><li class="alt"><span>document.write("</span><span class="tag">&lt;</span><span>%CsharpVoid();%</span><span class="tag">&gt;</span><span>");&nbsp;&nbsp;</span></span></li><li><span>//&nbsp;--</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span></span><span class="tag">&lt;/</span><span class="tag-name">script</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;script language="javascript"&gt;
&lt;!--
document.write("&lt;%CsharpVoid();%&gt;");
// --&gt;
&lt;/script&gt;</textarea><br /></span><span style="font-size: 10pt"><span style="font-size: small">可在页面中放一个按钮,把它设置为不可见style="display:none",然后,用脚本让此按钮点击 <br /></span>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span>document.all(</span><span class="string">"button1"</span><span>).click();&nbsp;&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">document.all("button1").click(); </textarea><span style="font-size: small"><br />在此按钮的C#后台中写事件代码,这就是最简单的脚本调用C#方法.</span></span><span style="font-size: small">&nbsp;</span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: medium"><strong><span style="font-size: small">二、C#与Javascript变量、函数之间的相互调用<br /></span></strong></span><span style="font-size: medium"><span style="font-size: x-small"><strong><span style="font-size: small">问题1：在JavaScript访问C#函数<br /></span></strong></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small"><strong>方法一</strong>：<br />1、首先建立一个按钮，在后台将调用或处理的内容写入button_click中;<br />2、在前台写一个js函数，内容为<br /></p>
<div class="dp-highlighter nogutter bg_javascript:nogutter">
<div class="bar">
<div class="tools"><strong>[javascript:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-c"><li class="alt"><span>document.getElementById(</span><span class="string">"btn1"</span><span>).click();&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="javascript:nogutter" rows="15" cols="50" name="code">document.getElementById("btn1").click();</textarea><br />3、在前台或后台调用js函数，激发click事件，等于访问后台c#函数；<br /><strong>方法二</strong>：</span></span></span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small">1、<span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: 10pt"><span style="font-size: small">后台代码</span></span></span></span>函数声明为</span><span style="font-size: small">public</span></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: 10pt"><span style="font-size: small">(protected也可以)<br /></span></p>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">string</span><span>&nbsp;ss()&nbsp;&nbsp;</span></li><li><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">return</span><span>(</span><span class="string">"a"</span><span>);&nbsp;&nbsp;</span></span></li><li><span>}&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">public string ss()
{
        return("a");
}</textarea><span style="font-size: small"><br />2、前台：在html脚本里用&lt;%=fucntion()%&gt;可以调用<br /></span></span></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: 10pt">
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">script</span><span>&nbsp;</span><span class="attribute">language</span><span>=</span><span class="attribute-value">javascript</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></li><li><span>&lt;!--&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span class="attribute">a</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">"&lt;%=ss()%&gt;"</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert(a);&nbsp;&nbsp;</span></li><li class="alt"><span>//&nbsp;--</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span></span><span class="tag">&lt;/</span><span class="tag-name">script</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;script language=javascript&gt;
&lt;!--
             var a = "&lt;%=ss()%&gt;";
             alert(a);
// --&gt;
&lt;/script&gt;</textarea><span style="font-size: small"> <br /></span><span style="font-size: small"><strong>方法三</strong>：<br /></span>
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">script</span><span>&nbsp;</span><span class="attribute">language</span><span>=</span><span class="attribute-value">"javascript"</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&lt;!--&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;__doPostBack(eventTarget,&nbsp;eventArgument)&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;</span><span class="attribute">theForm</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">document</span><span>.Form1;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//指</span><span class="attribute">runat</span><span>=</span><span class="attribute-value">server</span><span>的form&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">theForm.__EVENTTARGET.value</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">eventTarget</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">theFrom.__EVENTARGUMENT.value</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">eventArgument</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;theForm.submit();&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;//&nbsp;--</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span></span><span class="tag">&lt;/</span><span class="tag-name">script</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span></span><span class="tag">&lt;</span><span class="tag-name">input</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"Button1"</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"button"</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"Button1"</span><span>&nbsp;</span><span class="attribute">value</span><span>=</span><span class="attribute-value">"按钮"</span><span>&nbsp;&nbsp;&nbsp;</span><span class="attribute">onclick</span><span>=</span><span class="attribute-value">"javascript:__doPostBack('Button1','')"</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;script language="javascript"&gt;
  &lt;!--
    function __doPostBack(eventTarget, eventArgument)
    {
        var theForm = document.Form1;       //指runat=server的form
        theForm.__EVENTTARGET.value = eventTarget;
        theFrom.__EVENTARGUMENT.value = eventArgument;
        theForm.submit();
    }
  // --&gt;
&lt;/script&gt;
&lt;input id="Button1" type="button" name="Button1" value="按钮"   onclick="javascript:__doPostBack('Button1','')"/&gt;</textarea><span style="font-size: small"> <br />ASPX页面有包含asp:LinkButton或者带有AutoPostBack属性且其值为true的服务器控件时，ASP.NET会自动为页面生成下面的脚本：<br /></span>
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">input</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"hidden"</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"__EVENTTARGET"</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"__EVENTTARGET"</span><span>&nbsp;</span><span class="attribute">value</span><span>=</span><span class="attribute-value">""</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;&nbsp;</span></li><li><span></span><span class="tag">&lt;</span><span class="tag-name">input</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"hidden"</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"__EVENTARGUMENT"</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"__EVENTARGUMENT"</span><span>&nbsp;</span><span class="attribute">value</span><span>=</span><span class="attribute-value">""</span><span>&nbsp;</span><span class="tag">/&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /&gt; 
&lt;input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /&gt;</textarea><span style="font-size: small"> <br />这两个参数分别由隐藏的两个表单域__ EVENTTARGET和__ EVENTARGUMENT保存。&nbsp;<br />这两个隐藏的表单可以查找引起页面回送的控件ID和回送时的参数：<br /></span>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">string</span><span>&nbsp;target&nbsp;=&nbsp;Request.Params[</span><span class="string">"__EVENTTARGET"</span><span>];&nbsp;&nbsp;&nbsp;</span></li><li><span></span><span class="keyword">string</span><span>&nbsp;args&nbsp;=&nbsp;Request.Params[</span><span class="string">"__EVENTARGUMENT"</span><span>];&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">string target = Request.Params["__EVENTTARGET"]; 
string args = Request.Params["__EVENTARGUMENT"];</textarea><br /><span style="font-size: small">asp:Button和asp:ImageButton不是使用__doPostBack回送页面，所以使用这两个控件回送页面时，上面的代码是无效的。<br /><strong>方法四：</strong>1、前台：<br /></span>
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">script</span><span>&nbsp;</span><span class="attribute">language</span><span>=</span><span class="attribute-value">"javascript"</span><span class="tag">&gt;</span><span>&lt;!--&nbsp;&nbsp;</span></li><li><span>function&nbsp;SubmitKeyClick()&nbsp;&nbsp;</span></li><li class="alt"><span>{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span class="attribute">event.keyCode</span><span>&nbsp;==&nbsp;13)&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">event.cancelBubble</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">true</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">event.returnValue</span><span>&nbsp;=&nbsp;</span><span class="attribute-value">false</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="attribute">document.all.FunName.value</span><span>=</span><span class="attribute-value">"你要调用的函数名"</span><span>；&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.form[0].submit();&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li><li><span>//&nbsp;--</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span></span><span class="tag">&lt;/</span><span class="tag-name">script</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;</span></li><li class="alt"><span></span><span class="tag">&lt;</span><span class="tag-name">INPUT</span><span>&nbsp;</span><span class="attribute">onkeypress</span><span>=</span><span class="attribute-value">"SubmitKeyClick()"</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"aaa"</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"text"</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></span></li><li><span></span><span class="tag">&lt;</span><span class="tag-name">input</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"hidden"</span><span>&nbsp;</span><span class="attribute">name</span><span>=</span><span class="attribute-value">"FunName"</span><span class="tag">&gt;</span><span class="comments">&lt;!--用来存储你要调用的函数&nbsp;--&gt;</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;script language="javascript"&gt;&lt;!--
function SubmitKeyClick()
{
      if (event.keyCode == 13)
      {
          event.cancelBubble = true;
          event.returnValue = false;
          document.all.FunName.value="你要调用的函数名"；
          document.form[0].submit();
      }
}
// --&gt;
&lt;/script&gt;
 
&lt;INPUT onkeypress="SubmitKeyClick()" id="aaa" type="text"&gt;
&lt;input type="hidden" name="FunName"&gt;&lt;!--用来存储你要调用的函数 --&gt;</textarea><span style="font-size: small">&nbsp;<br /></span></span></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: 10pt"><span style="font-size: small">2、后台CS代码：<br /></span>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">public</span><span>&nbsp;Page_OnLoad()&nbsp;&nbsp;</span></li><li><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span><span class="keyword">if</span><span>&nbsp;(!Page.IsPost())&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">string</span><span>&nbsp;strFunName=Request.Form[</span><span class="string">"FunName"</span><span>]!=</span><span class="keyword">null</span><span>?Request.Form[</span><span class="string">"FunName"</span><span>]:</span><span class="string">""</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//根据传回来的值决定调用哪个函数 </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">switch</span><span>(strFunName)&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">case</span><span>&nbsp;</span><span class="string">"enter()"</span><span>:&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enter()&nbsp;;&nbsp;</span><span class="comment">//调用该函数 </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">break</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">case</span><span>&nbsp;</span><span class="string">"其他"</span><span>:&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//调用其他函数 </span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">break</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">default</span><span>:&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="comment">//调用默认函数 </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="keyword">break</span><span>;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;}&nbsp;&nbsp;</span></li><li><span>}&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;&nbsp;</span></li><li><span></span><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;enter()&nbsp;&nbsp;</span></span></li><li class="alt"><span>{&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;</span><span class="comment">//&#8230;&#8230;比如计算某值 </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>}&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">public Page_OnLoad()
{
  if (!Page.IsPost())
  {
    string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:"";
    //根据传回来的值决定调用哪个函数
    switch(strFunName)
    {
    case "enter()":
      enter() ; //调用该函数
       break;
    case "其他":
      //调用其他函数
      break;
    default:
      //调用默认函数
      break;
    }
  }
}
 
public void enter()
{
  //&#8230;&#8230;比如计算某值
}</textarea><span style="font-size: small">&nbsp;</span></span></span></span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small"><strong>问题2：在JavaScript访问C#变量</strong><br /></span></span></span></p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: small"><strong>方法一：<br /></strong></span><span style="font-size: small">1、通过页面上隐藏域访问<br /></span><span style="font-size: small"></p>
<div class="dp-highlighter nogutter bg_xhtml:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">input</span><span>&nbsp;</span><span class="attribute">id</span><span>=</span><span class="attribute-value">"xx"</span><span>&nbsp;</span><span class="attribute">type</span><span>=</span><span class="attribute-value">"hidden"</span><span>&nbsp;</span><span class="attribute">runat</span><span>=</span><span class="attribute-value">"server"</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="xhtml:nogutter:nocontrols" rows="15" cols="50" name="code">&lt;input id="xx" type="hidden" runat="server"&gt;</textarea> <br /><strong>方法二</strong>：</span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: small">1、如后台定义了:</span></p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: small"></p>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter:nocontrols">
<div class="bar"></div>
<ol class="dp-c"><li class="alt"><span class="keyword">public</span><span>&nbsp;</span><span class="keyword">string</span><span>&nbsp;n;&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter:nocontrols" rows="15" cols="50" name="code">public string n;</textarea> <br />2、</span><span style="font-size: small">前台js中引用该变量的格式为</span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: small"></p>
<div class="dp-highlighter nogutter bg_javascript:nogutter">
<div class="bar">
<div class="tools"><strong>[javascript:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-c"><li class="alt"><span class="string">'&lt;%=n%&gt;'</span><span>&nbsp;&nbsp;</span></li><li><span></span><span class="comment">//或 </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span></span><span class="string">"+&lt;%=n%&gt;+"</span><span>&nbsp;&nbsp;</span></span></li><li><span></span><span class="comment">//例： </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span></span><span class="keyword">var</span><span>&nbsp;ss=</span><span class="string">"&lt;%=n%&gt;"</span><span>&nbsp;&nbsp;</span></span></li></ol></div><textarea style="display: none" class="javascript:nogutter" rows="15" cols="50" name="code">'&lt;%=n%&gt;'
//或
"+&lt;%=n%&gt;+"
//例：
var ss="&lt;%=n%&gt;"
</textarea> <br /></span><span style="font-size: small"><strong>方法三</strong>：</span><span style="font-size: small">在服务器端变量赋值后在页面注册一段脚本<br /></span><span style="font-size: small">
<div class="dp-highlighter nogutter bg_c-sharp:nogutter">
<div class="bar">
<div class="tools"><strong>[c-sharp:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-c"><li class="alt"><span class="string">"&lt;script&nbsp;language='javascript'&gt;var&nbsp;temp="</span><span>&nbsp;+&nbsp;tmp&nbsp;+&nbsp;</span><span class="string">"&lt;/script&gt;"</span><span>&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter" rows="15" cols="50" name="code">"&lt;script language='javascript'&gt;var temp=" + tmp + "&lt;/script&gt;"</textarea><br />tmp是后台变量，然后js中可以直接访问temp获得值。</span> 
<p>&nbsp;</p>
<p style="margin: 0cm 0cm 10.5pt"><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small"><strong>问题3：在C#中访问JavaScript的已有变量<br /></strong><span style="font-size: small">方法一：<br />1、前台使用静态文本控件隐藏域，将js</span><span style="font-size: small">变量值写入其中；<br />2、后台用request["id"]</span><span style="font-size: small">来获取值；<br />方法二：<br /></span><span style="font-size: small">可以用cookie或session</span></span></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small"><strong>问题4：在C#中访问JavaScript函数</strong><br /></span><strong><span style="font-size: small">方法一：<br /></span></strong></span></span><span style="font-size: medium"><span style="font-size: x-small"></p>
<div class="dp-highlighter nogutter bg_c-sharp:nogutter">
<div class="bar">
<div class="tools"><strong>[c-sharp:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-c"><li class="alt"><span>Page.RegisterStartupScript(</span><span class="string">"ggg"</span><span>,"&lt;script&gt;SetVisible(1);&nbsp;&nbsp;</span></li><li><span>&lt;/script&gt;");&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="c-sharp:nogutter" rows="15" cols="50" name="code">Page.RegisterStartupScript("ggg","&lt;script&gt;SetVisible(1);
&lt;/script&gt;");</textarea><span style="font-size: small"> <br /><strong>方法二：</strong><br /></span></span></span><span style="font-size: medium"><span style="font-size: x-small"><span style="font-size: small">1、前台使用Literal类：<br /></span>
<div class="dp-highlighter nogutter bg_xhtml:nogutter">
<div class="bar">
<div class="tools"><strong>[xhtml:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-xml"><li class="alt"><span class="tag">&lt;</span><span class="tag-name">asp:Literal</span><span>&nbsp;</span><span class="attribute">ID</span><span>=</span><span class="attribute-value">"Literal1"</span><span>&nbsp;</span><span class="attribute">runat</span><span>=</span><span class="attribute-value">"server"</span><span class="tag">&gt;</span><span class="tag">&lt;/</span><span class="tag-name">asp:Literal</span><span class="tag">&gt;</span><span>&nbsp;&nbsp;</span></li></ol></div><textarea style="display: none" class="xhtml:nogutter" rows="15" cols="50" name="code">&lt;asp:Literal ID="Literal1" runat="server"&gt;&lt;/asp:Literal&gt;</textarea><span style="font-size: small"> <br />2、后台CS代码：<br /></span></span></span><span style="font-size: medium"><span style="font-size: x-small">
<div class="dp-highlighter nogutter bg_c-sharp:nogutter">
<div class="bar">
<div class="tools"><strong>[c-sharp:nogutter]</strong> <a class="ViewSource" title="view plain" href="http://blog.csdn.net/wonsoft/article/details/2595743#">view plain</a><a class="CopyToClipboard" title="copy" href="http://blog.csdn.net/wonsoft/article/details/2595743#">copy</a><a class="PrintSource" title="print" href="http://blog.csdn.net/wonsoft/article/details/2595743#">print</a><a class="About" title="?" href="http://blog.csdn.net/wonsoft/article/details/2595743#">?</a></div></div>
<ol class="dp-c"><li class="alt"><span class="keyword">private</span><span>&nbsp;</span><span class="keyword">void</span><span>&nbsp;Button2_Click(</span><span class="keyword">object</span><span>&nbsp;sender,&nbsp;System.EventArgs&nbsp;e)&nbsp;&nbsp;</span></li><li><span>{&nbsp;&nbsp;</span></li><li class="alt"><span>&nbsp;&nbsp;</span><span class="keyword">string</span><span>&nbsp;str;&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;str="&lt;mce:script&nbsp;language=</span><span class="string">'javascript'</span><span>&gt;&lt;!--&nbsp;&nbsp;</span></span></li><li class="alt"><span>";&nbsp;&nbsp;</span></li><li><span>&nbsp;&nbsp;str+=</span><span class="string">"selectRange()"</span><span>;&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;str+="&nbsp;&nbsp;</span></li><li><span></span><span class="comment">//&nbsp;--&gt;&lt;/mce:script&gt;"; </span><span>&nbsp;&nbsp;</span></span></li><li class="alt"><span>&nbsp;&nbsp;</span><span class="comment">//Literal1.Visible=true; </span><span>&nbsp;&nbsp;</span></span></li><li><span>&nbsp;&nbsp;Literal1.Text=str;&nbsp;&nbsp;</span></li><li class="alt"><span>}&nbsp;&nbsp;&nbsp;</span></li></ol></div><img src ="http://www.cnitblog.com/yide/aggbug/78059.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-12 21:17 <a href="http://www.cnitblog.com/yide/archive/2012/03/12/78059.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c#--script互相调用</title><link>http://www.cnitblog.com/yide/archive/2012/03/12/78058.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Mon, 12 Mar 2012 13:14:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/12/78058.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78058.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/12/78058.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78058.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78058.html</trackback:ping><description><![CDATA[<p align="right">&nbsp;</p>
<dd id="Article">
<p>From timothyblog<br />javaScript函数中执行C#代码中的函数： <br />方法一：1、首先建立一个按钮，在后台将调用或处理的内容写入button_click中; <br />2、在前台写一个js函数，内容为document.getElementById("btn1").click(); <br />3、在前台或后台调用js函数，激发click事件，等于访问后台<a class="keylink" href="http://www.2cto.com/kf/ware/cs/" target="_blank">c#</a>函数； </p>
<p>方法二：1、函数声明为public <br />后台代码(把public改成protected也可以) <br />public string ss() <br />{ <br />return("a"); <br />} <br />2、在html里用 &lt;%=fucntion()% &gt;可以调用 <br />前台脚本 <br />&lt;script language=javascript &gt; <br />var a = " &lt;%=ss()% &gt;"; <br />alert(a); <br />&lt;/script &gt; <br />方法三：1、 &lt;script language="javascript" &gt; <br />&lt;!-- <br />function __doPostBack(eventTarget, eventArgument) <br />{ <br />var theForm = document.Form1; //指runat=server的form <br />theForm.__EVENTTARGET.value = eventTarget; <br />theFrom.__EVENTARGUMENT.value = eventArgument; <br />theForm.submit(); <br />} <br />-- &gt; <br />&lt;/script &gt; <br />&lt;input id="Button1" type="button" name="Button1" value="按钮" onclick="javascript:__doPostBack( Button1 , )" &gt; </p>
<p>方法四： &lt;script language="javascript" &gt; <br />function SubmitKeyClick() <br />{ <br />if (event.keyCode == 13) <br />{ <br />event.cancelBubble = true; <br />event.returnValue = false; <br />document.all.FunName.value="你要调用的函数名"； <br />document.form[0].submit(); <br />} <br />} <br />&lt;/script &gt; </p>
<p>&lt;INPUT onkeypress="SubmitKeyClick()" id="aaa" type="text" &gt; <br />&lt;input type="hidden" name="FunName" &gt; 〈！--用来存储你要调用的函数 --〉 </p>
<p>在.CS里有： <br />public Page_OnLoad() <br />{ <br />if (!Page.IsPost()) <br />{ <br />string strFunName=Request.Form["FunName"]!=null?Request.Form["FunName"]:""; <br />//根据传回来的值决定调用哪个函数 <br />switch(strFunName) <br />{ <br />case "enter()": <br />enter() ; //调用该函数 <br />break; <br />case "其他": <br />//调用其他函数 <br />break; <br />default: <br />//调用默认函数 <br />break; <br />} <br />} <br />} </p>
<p>public void enter() <br />{ <br />//&#8230;&#8230;比如计算某值 <br />} </p>
<p>问题2.如何在JavaScript访问C#变量? <br />答案如下： <br />方法一：1、通过页面上隐藏域访问 &lt;input id="xx" type="hidden" runat="server" &gt; <br />方法二：1、如后台定义了PUBLIC STRING N;前台js中引用该变量的格式为 &lt;%=n% &gt; 或"+ &lt;%=n% &gt;+" <br />方法三：1、或者你可以在服务器端变量赋值后在页面注册一段脚本 <br />" &lt;script language= javascript &gt;var temp=" + tmp + " &lt;/script &gt;" <br />tmp是后台变量，然后js中可以直接访问temp获得值。 </p>
<p><br />3.如何在C#中访问JavaScript的已有变量? </p>
<p>答案如下： </p>
<p>方法一：1、前台使用静态文本控件隐藏域，将js变量值写入其中； <br />2、后台用request["id"]来获取值； </p>
<p>方法二：可以用cookie或session </p>
<p><br />4.如何在C#中访问JavaScript函数? <br />答案如下： <br />c#代码中执行javaScript函数： <br />方法一：1、Page.RegisterStartupScript("ggg"," &lt;script &gt;SetVisible(1); &lt;/script &gt;"); <br />方法二：使用Literal类，然后 <br />private void Button2_Click(object sender, System.EventArgs e) <br />{ <br />string str; <br />str=" &lt;script language= javascript &gt;"; <br />str+="selectRange()"; <br />str+=" &lt;/script &gt;"; <br />//Literal1.Visible=true; <br />Literal1.Text=str; <br />} <br /></p></dd>
<p align="right">&nbsp;</p><img src ="http://www.cnitblog.com/yide/aggbug/78058.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-12 21:14 <a href="http://www.cnitblog.com/yide/archive/2012/03/12/78058.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#--gridview</title><link>http://www.cnitblog.com/yide/archive/2012/03/09/78013.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 09 Mar 2012 14:27:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/09/78013.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78013.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/09/78013.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78013.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78013.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: &nbsp; 显示表格数据是软件开发中的一个周期性任务。ASP.NET 提供了许多工具来在网格中显示表格数据，例如 GridView 控件。通过使用 GridView 控件，您可以显示、编辑和删除多种不同的数据源（例如数据库、XML 文件和公开数据的业务对象）中的数据。&nbsp;1. GridView数据绑定基础&nbsp;&nbsp;&nbsp; GridView大部份场合下都是用来绑定数据源...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yide/archive/2012/03/09/78013.html'>阅读全文</a><img src ="http://www.cnitblog.com/yide/aggbug/78013.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-09 22:27 <a href="http://www.cnitblog.com/yide/archive/2012/03/09/78013.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Sqlserver--like参数加百分号</title><link>http://www.cnitblog.com/yide/archive/2012/03/09/78012.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 09 Mar 2012 13:18:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/09/78012.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78012.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/09/78012.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78012.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78012.html</trackback:ping><description><![CDATA[<div><span style="font-size: 12px;">&nbsp;</span>Sqlserver--like参数加%<span style="font-size: 12px;"><br /></span><span style="font-size: 12px;"><br />&nbsp;string sql = "select hr_key , user_id,user_name from &nbsp;hruser where user_id like @userid " ;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; SqlConnection Sqlcon = new SqlConnection(ConfigurationManager.AppSettings["prConnection"]);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; SqlCommand sqlComm = new SqlCommand(sql, Sqlcon);</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;// sqlComm.Parameters.Add("@userid", SqlDbType.VarChar);//添加参数</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;// sqlComm.Parameters.Add(new SqlParameter("@userid", string.Format("{0}%", tbUserId.Text)));</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; sqlComm.Parameters.Add(new SqlParameter("@userid", string.Format("{0}%", tbUserId.Text)));</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; //sqlComm.Parameters["@userid"].Value = tbUserId.Text ;//为参数赋值</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; Sqlcon.Open();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;// sqlComm.ExecuteNonQuery();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; //Sqlcon.Close();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; SqlDataReader Dreader = sqlComm.ExecuteReader();</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; gvHrUser.DataSource = Dreader;&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; gvHrUser.DataBind();</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; Sqlcon.Close();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;</span></div><img src ="http://www.cnitblog.com/yide/aggbug/78012.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-09 21:18 <a href="http://www.cnitblog.com/yide/archive/2012/03/09/78012.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#--sql实例</title><link>http://www.cnitblog.com/yide/archive/2012/03/09/78011.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 09 Mar 2012 12:06:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/09/78011.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78011.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/09/78011.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78011.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78011.html</trackback:ping><description><![CDATA[&nbsp; 
<p style="text-align: left;background: white; mso-pagination: widow-orphan; mso-margin-top-alt: auto; mso-margin-bottom-alt: auto; mso-outline-level: 3" class="MsoNormal" align="left"><strong><span style="font-family: 'Arial','sans-serif'; color: #17365d; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">sql</span></strong><strong><span style="font-family: 宋体; color: #17365d; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">用法总结</span></strong><strong><span style="font-family: 'Arial','sans-serif'; color: #17365d; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">:</span></strong><span style="font-family: 'Arial','sans-serif'; color: #17365d; mso-font-kerning: 0pt; mso-bidi-font-size: 10.5pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">1.</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">查询语句</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">adpter</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">里写</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">sql,</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">执行后把结果赋值给新建的</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">dataset </span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">对象</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">ds</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">，即可在</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">gridview</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">显示。</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">&nbsp;&nbsp; <o:p></o:p></span></strong></p>
<p style="text-align: left;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlConnection con = new SqlConnection("server=ZMQHBD2007;database=data;uid=sa;pwd=123;");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span>//</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">上面这句等价于：</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="mso-spacerun: yes">&nbsp;</span>//private static string constring="&#8221;; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter sda = new SqlDataAdapter("select * from category", con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">上面这句等价于：</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;&nbsp; //string cmd= "select * from category";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp; // SqlDataAdapter sda = new SqlDataAdapter(cmd,con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sda.Fill(ds, "category");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">下面这</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">5</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">个语句等价</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; //this.GridView1.DataSource = ds;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; //this.GridView1.DataSource = ds.Tables[0];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; //this.GridView1.DataSource = ds.Tables["customers"];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp; //this.GridView1.DataSource = ds.Tables[0].DefaultView;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataSource = ds.Tables["category"].DefaultView;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataBind();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Close(); <o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">注：利用</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlConnection</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlDataAdapter</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">DataSet</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实现表内容在</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">GridView</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">中显示。</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">&nbsp;&nbsp;<o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">2.sqlcommand</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">执行</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">sql,</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">然后赋值给</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">adapter</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">的</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">command</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">方法</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">, adapter</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">再填充数据给新建</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">dataset</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">对象的</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">ds,</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">然后显示</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection con = new SqlConnection(&#8230;);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand("select * from category", con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataAdapter sda = new SqlDataAdapter();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sda.SelectCommand = cmd;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">第三句话和第五句话可写为：</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; //sda.SelectCommand = new SqlCommand("select * from category", con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet ds = new DataSet();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sda.Fill(ds, "category");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataSource = ds.Tables["category"].DefaultView;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataBind();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Close();<o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">利用</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlConnection</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlCommand</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlDataAdapter</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">和</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">DataSet</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实现表内容在</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">GridView</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">中显示。</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ////</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">我最经常用这一种</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">,</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">同时连接对象是整个程序的公共对象</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">,</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">所以我一般会把数据库连接封装到一个类中</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">,</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">这样就可以在程序的任何地方随时调用</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">3.sqlcommand</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">执行</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">sql,</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">然后执行</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">reader</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">属性，赋值给</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">datareader</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">对象，</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">reader</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">对象作为</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">ds.<o:p></o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp; SqlConnection con = new SqlConnection("&#8230;..");&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">双引号中的最后一个分号可以去掉</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand cmd = new SqlCommand("select * from category", con);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">上面这句可写为：</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //SqlCommand cmd = new SqlCommand();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //cmd.CommandText = "select * from category";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //cmd.Connection = con;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //cmd.CommandType = CommandType.Text; //</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">这条语句是多余的</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">,</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">因为默认就是</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">Text <br />&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataReader sdr = cmd.ExecuteReader();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataSource = sdr;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.GridView1.DataBind();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sdr.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; con.Close();<o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">利用</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlConnection</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlCommand</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SqlDataReader</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">实现表内容在</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">GridView</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">中显示。</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">注：加参数</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></strong></p>
<p style="text-align: left; text-indent: 22.5pt; mso-char-indent-count: 2.5; mso-layout-grid-align: none" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US">SqlCommand sqlComm = new SqlCommand(sql, Sqlcon);<o:p></o:p></span></p>
<p style="text-align: left; mso-layout-grid-align: none" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>sqlComm.Parameters.Add("@userid", SqlDbType.Int);//</span><span style="font-family: 新宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-no-proof: yes">添加参数</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; mso-layout-grid-align: none" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>sqlComm.Parameters["@userid"].Value = Convert.ToInt32( tbUserId.Text) ;//</span><span style="font-family: 新宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial; mso-no-proof: yes">为参数赋值</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; mso-layout-grid-align: none" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 新宋体; mso-themecolor: text2; mso-themeshade: 191; mso-no-proof: yes" lang="EN-US"><span style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p></o:p></span></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left; margin-bottom: 7.5pt;background: white; mso-pagination: widow-orphan" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">4.</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">其他更新语句</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">&nbsp;&nbsp;&nbsp; <br />//</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">如果</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">SQL</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">语句是</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">Delete</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">Update</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">、</span></strong><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">Insert&nbsp;&nbsp;</span></strong><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"> <br />SqlComman&nbsp;&nbsp; cmd=new&nbsp;&nbsp; SqlCommand();&nbsp;&nbsp; <br />cmd.CommandText=SQL</span><span style="font-family: 宋体; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-themecolor: text2; mso-themeshade: 191; mso-ascii-font-family: Arial; mso-hansi-font-family: Arial; mso-bidi-font-family: Arial">语句</span><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-font-kerning: 0pt; mso-fareast-font-family: 宋体; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US">;&nbsp;&nbsp; <br />cmd.CommandType=System.Data.CommandType.Text;&nbsp;&nbsp; <br />cmd.Connection=mycon;&nbsp;&nbsp; <br />cmd.ExcuteNoQuery();&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; <br />mycon.Close();<o:p></o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left" class="MsoNormal" align="left"><strong style="mso-bidi-font-weight: normal"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></strong></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p>
<p style="text-align: left" class="MsoNormal" align="left"><span style="font-family: 'Arial','sans-serif'; color: #17365d; font-size: 9pt; mso-themecolor: text2; mso-themeshade: 191" lang="EN-US"><o:p>&nbsp;</o:p></span></p> <img src ="http://www.cnitblog.com/yide/aggbug/78011.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-09 20:06 <a href="http://www.cnitblog.com/yide/archive/2012/03/09/78011.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title> sql 2005中real，float，decimal的区别</title><link>http://www.cnitblog.com/yide/archive/2012/03/09/78010.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 09 Mar 2012 09:03:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/09/78010.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78010.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/09/78010.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78010.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78010.html</trackback:ping><description><![CDATA[<pre id="best-answer-content"  mb10"="" style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; font-size: 14px; background-color: #fffcf6; "><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">decimal 数据类型最多可存储 38 个数字，所有数字都能够放到小数点的右边。decimal 数据类型存储了一个准确（精确）的数字表达法；不存储值的近似值。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">定义 decimal 的列、变量和参数的两种特性如下：&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&#8226; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;p &nbsp; 小数点左边和右边数字之和，不包括小数点。如 123.45,则 p=5，s=2。&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定精度或对象能够控制的数字个数。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&#8226; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s&nbsp;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">指定可放到小数点右边的小数位数或数字个数。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">p 和 s 必须遵守以下规则：0 &lt;= s &lt;= p &lt;= 38。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">numeric 和 decimal 数据类型的默认最大精度值是 38。在 Transact-SQL 中，numeric 与 decimal 数据类型在功能上等效。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">当数据值一定要按照指定精确存储时，可以用带有小数的 decimal 数据类型来存储数字。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">float 和 real 数据</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">float 和 real 数据类型被称为近似的数据类型。在近似数字数据类型方面，float 和 real 数据的使用遵循 IEEE 754 标准。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">近似数字数据类型并不存储为多数数字指定的精确值，它们只储存这些值的最近似值。在很多应用程序中，指定值与存储值之间的微小差异并不明显。但有时这些差异也值得引起注意。由于 float 和 real 数据类型的这种近似性，当要求精确的数字状态时，比如在财务应用程序中，在那些需要舍入的操作中，或在等值核对的操作中，就不使用这些数据类型。这时就要用 integer、decimal、money 或 smallmone 数据类型。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">在 WHERE 子句搜索条件中（特别是 = 和 &lt;&gt; 运算符），应避免使用 float 或 real 列。最好限制使用 float 和 real 列做 &gt; 或 &lt; 的比较。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">IEEE 754 规格提供了四种舍入模式：舍入到最接近的值、上舍入、下舍入和舍入到零。Microsoft&#174; SQL Server&#8482; 使用上舍入。所有的数值必须精确到确定的精度，但会产生细小的浮点值变化。因为浮点数字的二进制表示法可以采用很多合法舍入规则中的任意一条，因此我们不可能可靠地量化一个浮点值。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">转换 decimal 和 numeric 数据</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">对于 decimal 和 numeric 数据类型，Microsoft&#174; SQL Server&#8482; 将精度和小数位数的每个特定组合看作是不同的数据类型。例如，decimal(5,5) 和 decimal(5,0) 被当作不同的数据类型。(因此在编存储过程当中使用的变量采用Real 或 Float,而不采用decimal类型)</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">在 Transact-SQL 语句中，带有小数点的常量自动转换为 numeric 数据值，且必然使用最小的精度和小数位数。例如，常量 12.345 被转换为 numeric 值，其精度为 5，小数位为 3。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">从 decimal 或 numeric 向 float 或 real 转换会导致精度损失。从 int、smallint、tinyint、float、real、money 或 smallmoney 向 decimal 或 numeric 转换会导致溢出。</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">默认情况下，在将数字转换为较低精度和小数位数的 decimal 或 numeric 值时，SQL Server 使用舍入法。然而，如果 SET ARITHABORT 选项为 ON，当发生溢出时，SQL Server 会出现错误。若仅损失精度和小数位数，则不会产生错误。</span></div><div><span style="font-size: 12px;"><br /></span></div><div>&nbsp;</div><div><span style="font-size: 12px;"><br /></span></div><div>&nbsp;</div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">Float 的科学计数法与值的问题，问题的根源在于 float 类型本身是一种不精确的数据表示方法, 也就是说, 你放一个数据进去, 拿出来的时候可能会存在一点点点误差, 而这点点点误差在做数据比较的时候就会导致数据不一致.</span></div></pre><img src ="http://www.cnitblog.com/yide/aggbug/78010.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-09 17:03 <a href="http://www.cnitblog.com/yide/archive/2012/03/09/78010.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C# 获取文件名及扩展名</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/78003.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 11:36:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/78003.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78003.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/78003.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78003.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78003.html</trackback:ping><description><![CDATA[<table width="100%" border="0" cellspacing="0" cellpadding="0" style="height: 26px; font-family: Arial; background-color: #d8c99c; "><tbody><tr><td nowrap="" style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; line-height: 18px; "><div style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; padding-top: 2px; padding-right: 4px; padding-bottom: 0px; padding-left: 4px; "><font color="#432f24"><span style="font-size: 14px;"><strong><br /></strong></span></font></div></td><td nowrap="" align="right" style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; "></td><td width="7" style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; ">&nbsp;</td></tr></tbody></table><div id="m_blog" style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; line-height: 18px; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 10px; background-color: #d8c99c; color: #888888; text-align: center; overflow-x: hidden; "><div style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 26px; font-weight: bold; text-align: left; border-left-width: 5px; border-left-color: #f0461f; text-indent: 8px; overflow-x: hidden; overflow-y: hidden; ">C# 获取文件名及扩展名</div><div style="font-family: Verdana; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 10px; margin-top: 0px; margin-right: 0px; margin-bottom: 8px; margin-left: 12px; text-align: left; ">2011年12月20日 星期二 22:02</div><table style="table-layout: fixed; width: 960px; "><tbody><tr><td style="word-wrap: break-word; word-break: break-all; filter: none; font-size: 12px; line-height: 18px; visibility: visible !important; zoom: 1 !important;"><div id="blog_text" style="word-wrap: break-word; word-break: break-all; filter: none; overflow: hidden; visibility: visible !important; zoom: 1 !important; position: relative !important;"><p style="line-height: normal; ">C# 获取文件名及扩展名</p><p style="line-height: normal; ">string aFirstName = aFile.Substring(aFile.LastIndexOf("\\") + 1, (aFile.LastIndexOf(".") - aFile.LastIndexOf("\\") - 1));&nbsp; //文件名<br />string aLastName = aFile.Substring(aFile.LastIndexOf(".") + 1, (aFile.Length - aFile.LastIndexOf(".") - 1));&nbsp;&nbsp; //扩展名</p><p style="line-height: normal; ">string strFilePaht="文件路径";<br />Path.GetFileNameWithoutExtension(strFilePath);这个就是获取文件名的</p><p style="line-height: normal; ">。。。。。。。。。。。。。。。。</p><p style="line-height: normal; ">详见网址：<span style="color: #888888; text-align: center;"><a href="http://dalaoyer.com/article.php?id=375" title="http://dalaoyer.com/article.php?id=375">http://dalaoyer.com/article.php?id=375</a></span></p><p style="line-height: normal; "><br /></p></div></td></tr></tbody></table></div><img src ="http://www.cnitblog.com/yide/aggbug/78003.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 19:36 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/78003.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ContentType--文件下载类型</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/78002.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 11:30:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/78002.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/78002.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/78002.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/78002.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/78002.html</trackback:ping><description><![CDATA[<div style="font-family: verdana; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: red; border-right-color: red; border-bottom-color: red; border-left-color: red; border-image: initial; padding-top: 10px; padding-right: 10px; padding-bottom: 10px; padding-left: 0px; font-size: 13px; font-weight: bold; line-height: 18px; text-align: left; "><img src="http://www.cnblogs.com/skins/bj2008/images/fire.gif" border="0" align="absmiddle" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; "  alt="" /><a id="cb_post_title_url" href="http://www.cnblogs.com/chenghm2003/archive/2008/10/19/1314703.html" style="border-bottom-style: dotted; border-bottom-width: 1px; border-bottom-color: #efefef; padding-bottom: 10px; color: #087da8; ">Response.ContentType 详细列表</a></div><div id="cnblogs_post_body" style="font-family: verdana; line-height: 1.5; font-size: 13px; text-align: left; ">不同的ContentType 会影响客户端所看到的效果.默认的ContentType为 text/html 也就是网页格式.<br />代码如:<br /><div>&lt;% response.ContentType ="text/html" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/ContentType.html" --&gt;</div><br />显示的为网页,而<br /><div>&lt;% response.ContentType ="text/plain" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/sscript/ContentType.html" --&gt;</div><br />则会显示html原代码.<br /><br />以下为一些常用的 ContentType<br /><strong>GIF images</strong>&nbsp;<br /><div>&lt;% response.ContentType ="image/gif" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myimage.gif" --&gt;</div><br /><strong>JPEG images&nbsp;</strong><br /><div>&lt;% response.ContentType ="image/jpeg" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myimage.jpeg" --&gt;</div><br /><strong>TIFF images</strong>&nbsp;<br /><div>&lt;% response.ContentType ="image/tiff" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myimage.tiff" --&gt;</div><br /><strong>MICROSOFT WORD document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/msword" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.doc" --&gt;</div><br /><strong>RTF document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/rtf" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.rtf" --&gt;</div><br /><strong>MICROSOFT EXCEL document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/x-excel" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.xls" --&gt;</div><br /><strong>MICROSOFT POWERPOINT document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/ms-powerpoint" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.pff" --&gt;</div><br /><strong>PDF document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/pdf" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.pdf" --&gt;</div><br /><strong>ZIP document</strong>&nbsp;<br /><div>&lt;% response.ContentType ="application/zip" %&gt;&nbsp;<br />&lt;!--＃i nclude virtual="/myfile.zip" --&gt;</div><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; "><br /><br />下面是更详细的ContentType<br />'ez' =&gt; 'application/andrew-inset',&nbsp;<br />'hqx' =&gt; 'application/mac-binhex40',&nbsp;<br />'cpt' =&gt; 'application/mac-compactpro',&nbsp;<br />'doc' =&gt; 'application/msword',&nbsp;<br />'bin' =&gt; 'application/octet-stream',&nbsp;<br />'dms' =&gt; 'application/octet-stream',&nbsp;<br />'lha' =&gt; 'application/octet-stream',&nbsp;<br />'lzh' =&gt; 'application/octet-stream',&nbsp;<br />'exe' =&gt; 'application/octet-stream',&nbsp;<br />'class' =&gt; 'application/octet-stream',&nbsp;<br />'so' =&gt; 'application/octet-stream',&nbsp;<br />'dll' =&gt; 'application/octet-stream',&nbsp;<br />'oda' =&gt; 'application/oda',&nbsp;<br />'pdf' =&gt; 'application/pdf',&nbsp;<br />'ai' =&gt; 'application/postscript',&nbsp;<br />'eps' =&gt; 'application/postscript',&nbsp;<br />'ps' =&gt; 'application/postscript',&nbsp;<br />'smi' =&gt; 'application/smil',&nbsp;<br />'smil' =&gt; 'application/smil',&nbsp;<br />'mif' =&gt; 'application/vnd.mif',&nbsp;<br />'xls' =&gt; 'application/vnd.ms-excel',&nbsp;<br />'ppt' =&gt; 'application/vnd.ms-powerpoint',&nbsp;<br />'wbxml' =&gt; 'application/vnd.wap.wbxml',&nbsp;<br />'wmlc' =&gt; 'application/vnd.wap.wmlc',&nbsp;<br />'wmlsc' =&gt; 'application/vnd.wap.wmlscriptc',&nbsp;<br />'bcpio' =&gt; 'application/x-bcpio',&nbsp;<br />'vcd' =&gt; 'application/x-cdlink',&nbsp;<br />'pgn' =&gt; 'application/x-chess-pgn',&nbsp;<br />'cpio' =&gt; 'application/x-cpio',&nbsp;<br />'csh' =&gt; 'application/x-csh',&nbsp;<br />'dcr' =&gt; 'application/x-director',&nbsp;<br />'dir' =&gt; 'application/x-director',&nbsp;<br />'dxr' =&gt; 'application/x-director',&nbsp;<br />'dvi' =&gt; 'application/x-dvi',&nbsp;<br />'spl' =&gt; 'application/x-futuresplash',&nbsp;<br />'gtar' =&gt; 'application/x-gtar',&nbsp;<br />'hdf' =&gt; 'application/x-hdf',&nbsp;<br />'js' =&gt; 'application/x-javascript',&nbsp;<br />'skp' =&gt; 'application/x-koan',&nbsp;<br />'skd' =&gt; 'application/x-koan',&nbsp;<br />'skt' =&gt; 'application/x-koan',&nbsp;<br />'skm' =&gt; 'application/x-koan',&nbsp;<br />'latex' =&gt; 'application/x-latex',&nbsp;<br />'nc' =&gt; 'application/x-netcdf',&nbsp;<br />'cdf' =&gt; 'application/x-netcdf',&nbsp;<br />'sh' =&gt; 'application/x-sh',&nbsp;<br />'shar' =&gt; 'application/x-shar',&nbsp;<br />'swf' =&gt; 'application/x-shockwave-flash',&nbsp;<br />'sit' =&gt; 'application/x-stuffit',&nbsp;<br />'sv4cpio' =&gt; 'application/x-sv4cpio',&nbsp;<br />'sv4crc' =&gt; 'application/x-sv4crc',&nbsp;<br />'tar' =&gt; 'application/x-tar',&nbsp;<br />'tcl' =&gt; 'application/x-tcl',&nbsp;<br />'tex' =&gt; 'application/x-tex',&nbsp;<br />'texinfo' =&gt; 'application/x-texinfo',&nbsp;<br />'texi' =&gt; 'application/x-texinfo',&nbsp;<br />'t' =&gt; 'application/x-troff',&nbsp;<br />'tr' =&gt; 'application/x-troff',&nbsp;<br />'roff' =&gt; 'application/x-troff',&nbsp;<br />'man' =&gt; 'application/x-troff-man',&nbsp;<br />'me' =&gt; 'application/x-troff-me',&nbsp;<br />'ms' =&gt; 'application/x-troff-ms',&nbsp;<br />'ustar' =&gt; 'application/x-ustar',&nbsp;<br />'src' =&gt; 'application/x-wais-source',&nbsp;<br />'xhtml' =&gt; 'application/xhtml+xml',&nbsp;<br />'xht' =&gt; 'application/xhtml+xml',&nbsp;<br />'zip' =&gt; 'application/zip',&nbsp;<br />'au' =&gt; 'audio/basic',&nbsp;<br />'snd' =&gt; 'audio/basic',&nbsp;<br />'mid' =&gt; 'audio/midi',&nbsp;<br />'midi' =&gt; 'audio/midi',&nbsp;<br />'kar' =&gt; 'audio/midi',&nbsp;<br />'mpga' =&gt; 'audio/mpeg',&nbsp;<br />'mp2' =&gt; 'audio/mpeg',&nbsp;<br />'mp3' =&gt; 'audio/mpeg',&nbsp;<br />'aif' =&gt; 'audio/x-aiff',&nbsp;<br />'aiff' =&gt; 'audio/x-aiff',&nbsp;<br />'aifc' =&gt; 'audio/x-aiff',&nbsp;<br />'m3u' =&gt; 'audio/x-mpegurl',&nbsp;<br />'ram' =&gt; 'audio/x-pn-realaudio',&nbsp;<br />'rm' =&gt; 'audio/x-pn-realaudio',&nbsp;<br />'rpm' =&gt; 'audio/x-pn-realaudio-plugin',&nbsp;<br />'ra' =&gt; 'audio/x-realaudio',&nbsp;<br />'wav' =&gt; 'audio/x-wav',&nbsp;<br />'pdb' =&gt; 'chemical/x-pdb',&nbsp;<br />'xyz' =&gt; 'chemical/x-xyz',&nbsp;<br />'bmp' =&gt; 'image/bmp',&nbsp;<br />'gif' =&gt; 'image/gif',&nbsp;<br />'ief' =&gt; 'image/ief',&nbsp;<br />'jpeg' =&gt; 'image/jpeg',&nbsp;<br />'jpg' =&gt; 'image/jpeg',&nbsp;<br />'jpe' =&gt; 'image/jpeg',&nbsp;<br />'png' =&gt; 'image/png',&nbsp;<br />'tiff' =&gt; 'image/tiff',&nbsp;<br />'tif' =&gt; 'image/tiff',&nbsp;<br />'djvu' =&gt; 'image/vnd.djvu',&nbsp;<br />'djv' =&gt; 'image/vnd.djvu',&nbsp;<br />'wbmp' =&gt; 'image/vnd.wap.wbmp',&nbsp;<br />'ras' =&gt; 'image/x-cmu-raster',&nbsp;<br />'pnm' =&gt; 'image/x-portable-anymap',&nbsp;<br />'pbm' =&gt; 'image/x-portable-bitmap',&nbsp;<br />'pgm' =&gt; 'image/x-portable-graymap',&nbsp;<br />'ppm' =&gt; 'image/x-portable-pixmap',&nbsp;<br />'rgb' =&gt; 'image/x-rgb',&nbsp;<br />'xbm' =&gt; 'image/x-xbitmap',&nbsp;<br />'xpm' =&gt; 'image/x-xpixmap',&nbsp;<br />'xwd' =&gt; 'image/x-xwindowdump',&nbsp;<br />'igs' =&gt; 'model/iges',&nbsp;<br />'iges' =&gt; 'model/iges',&nbsp;<br />'msh' =&gt; 'model/mesh',&nbsp;<br />'mesh' =&gt; 'model/mesh',&nbsp;<br />'silo' =&gt; 'model/mesh',&nbsp;<br />'wrl' =&gt; 'model/vrml',&nbsp;<br />'vrml' =&gt; 'model/vrml',&nbsp;<br />'css' =&gt; 'text/css',&nbsp;<br />'html' =&gt; 'text/html',&nbsp;<br />'htm' =&gt; 'text/html',&nbsp;<br />'asc' =&gt; 'text/plain',&nbsp;<br />'txt' =&gt; 'text/plain',&nbsp;<br />'rtx' =&gt; 'text/richtext',&nbsp;<br />'rtf' =&gt; 'text/rtf',&nbsp;<br />'sgml' =&gt; 'text/sgml',&nbsp;<br />'sgm' =&gt; 'text/sgml',&nbsp;<br />'tsv' =&gt; 'text/tab-separated-values',&nbsp;<br />'wml' =&gt; 'text/vnd.wap.wml',&nbsp;<br />'wmls' =&gt; 'text/vnd.wap.wmlscript',&nbsp;<br />'etx' =&gt; 'text/x-setext',&nbsp;<br />'xsl' =&gt; 'text/xml',&nbsp;<br />'xml' =&gt; 'text/xml',&nbsp;<br />'mpeg' =&gt; 'video/mpeg',&nbsp;<br />'mpg' =&gt; 'video/mpeg',&nbsp;<br />'mpe' =&gt; 'video/mpeg',&nbsp;<br />'qt' =&gt; 'video/quicktime',&nbsp;<br />'mov' =&gt; 'video/quicktime',&nbsp;<br />'mxu' =&gt; 'video/vnd.mpegurl',&nbsp;<br />'avi' =&gt; 'video/x-msvideo',&nbsp;<br />'movie' =&gt; 'video/x-sgi-movie',&nbsp;<br />'ice' =&gt; 'x-conference/x-cooltalk'&nbsp;<br /><br />//---------------------下面是从资源文件获取图片。并显示<br />&nbsp;public class GetImage<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static System.Drawing.Image GetSrc(string name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Resources.ResourceManager rm = new ResourceManager("ClassLibrary.ResourceTestImg",<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Reflection.Assembly.GetExecutingAssembly());//ResourceTestImg为资源文件名称,ClassLibrary//为命名空间<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return rm.GetObject(name) as System.Drawing.Image;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; }<br /><br />显示代码<br />&nbsp;protected void Page_Load(object sender, EventArgs e)<br />&nbsp;{</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.Drawing.Image img = ClassLibrary.GetImage.GetSrc("_15958260");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //_15958260为在ResourceTestImg.resx资源管理窗口中看到资源图片名称<br />&nbsp;&nbsp;&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; img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);<br />}</p></div><img src ="http://www.cnitblog.com/yide/aggbug/78002.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 19:30 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/78002.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sqlserver-2008--file上传下载</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77996.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 08:53:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77996.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77996.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77996.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77996.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77996.html</trackback:ping><description><![CDATA[<table style="table-layout: fixed; font-family: Arial; width: 960px; "><tbody><tr><td style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; "><div id="blog_text" style="word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 20px; color: #333333; overflow-x: hidden; overflow-y: hidden; position: relative !important; border-image: initial; "><p style="line-height: normal; ">数据库：sql server 2008 express</p><p style="line-height: normal; ">表：</p><p style="line-height: normal; ">CREATE TABLE [dbo].[filetest](<br />&nbsp;&nbsp; &nbsp;[id] [int] IDENTITY(1,1) NOT NULL,<br />&nbsp;&nbsp; &nbsp;[fs] [varbinary](max) NULL<br />) ON [PRIMARY]</p><p style="line-height: normal; ">&nbsp;</p><p style="line-height: normal; ">写入：</p><p style="line-height: normal; ">&nbsp;protected void Button1_Click(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlConnection sconn =new SqlConnection("Server=192.168.1.11\\sqlexpress,1433; Database=DBCustomer; User Id=sa; Password=1234");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string FileName;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string FilePath = this.FileUpload1.PostedFile.FileName;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Stream FileStream = FileUpload1.PostedFile.InputStream;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileName = Path.GetFileName(FilePath);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileName != null &amp;&amp; FileName != "")<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; int FileLen = FileUpload1.PostedFile.ContentLength;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; byte[] FileData = new Byte[FileLen];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int n = FileStream.Read(FileData, 0, FileLen);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FileStream.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand com = new SqlCommand();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.CommandText = "insert into filetest(fs) values(@fs)";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters.Add(new System.Data.SqlClient.SqlParameter("@fs", System.Data.SqlDbType.Image, FileData.Length, "fs"));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Connection = sconn;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Parameters["@fs"].Value = FileData;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Connection.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.ExecuteNonQuery();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; com.Connection.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="line-height: normal; ">读取</p><p style="line-height: normal; ">SqlConnection sconn =new SqlConnection("Server=192.168.1.11\\sqlexpress,1433; Database=DBCustomer; User Id=sa; Password=1234");</p><p style="line-height: normal; ">//根据不同文件类型，设定ContentType 。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Response.ContentType = "application/vnd.ms-excel";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.ContentType = "application/pdf";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Response.Clear();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlCommand selcom = new SqlCommand();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selcom.CommandText = "select fs from filetest order by id desc";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selcom.Connection = sconn;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selcom.Connection.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SqlDataReader dr = selcom.ExecuteReader();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr.Read();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Byte[] b = new Byte[(dr.GetBytes(0, 0, null, 0, int.MaxValue))];<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr.GetBytes(0, 0, b, 0, b.Length);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dr.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; selcom.Connection.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.IO.Stream fs = this.Response.OutputStream;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fs.Write(b, 0, b.Length);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fs.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.Response.End();</p></div></td></tr></tbody></table><img src ="http://www.cnitblog.com/yide/aggbug/77996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 16:53 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>把word存入sqlserver</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77991.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 07:05:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77991.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77991.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77991.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77991.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77991.html</trackback:ping><description><![CDATA[<p style="line-height:19.5pt;background:white"><span style="font-size: 9pt; font-family: Simsun, serif; ">/*</span><span style="font-size: 9pt; ">如何把</span><span style="font-size: 9pt; font-family: Simsun, serif; ">word</span><span style="font-size: 9pt; ">存入</span><span style="font-size: 9pt; font-family: Simsun, serif; ">sqlserver</span><span style="font-size: 9pt; ">数据库</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">并且读取的时候还是用</span><span style="font-size: 9pt; font-family: Simsun, serif; ">word</span><span style="font-size: 9pt; ">读取</span><span style="font-size: 9pt; font-family: Simsun, serif; ">.<br /> </span><span style="font-size: 9pt; ">建立</span><span style="font-size: 9pt; font-family: Simsun, serif; ">table<br /> create table myimages(sno int,imgfield image);<br /> </span><span style="font-size: 9pt; ">建立</span><span style="font-size: 9pt; font-family: Simsun, serif; ">c#</span><span style="font-size: 9pt; ">工程</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">添加引用</span><span style="font-size: 9pt; font-family: Simsun, serif; ">(reference-&gt;add-&gt;brower-&gt;office</span><span style="font-size: 9pt; ">安装文件夹</span><span style="font-size: 9pt; font-family: Simsun, serif; ">-&gt;office11-&gt;msword.ole,</span><span style="font-size: 9pt; ">然后什么都不用问了</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">等待</span><span style="font-size: 9pt; font-family: Simsun, serif; ">...,</span><span style="font-size: 9pt; ">然后拷贝下代码</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">具体功能见注释</span><span style="font-size: 9pt; font-family: Simsun, serif; ">*/<br /> using system;<br /> using system.drawing;<br /> using system.collections;<br /> using system.componentmodel;<br /> using system.windows.forms;<br /> using system.data;<br /> using system.data.sqlclient;<br /> using system.io;</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">namespace writefile<br /> {<br /> &nbsp;/// &lt;summary&gt;<br /> &nbsp;/// summary description for form1.<br /> &nbsp;/// &lt;/summary&gt;<br /> &nbsp;public class form1 : system.windows.forms.form<br /> &nbsp;{<br /> &nbsp;&nbsp;private system.windows.forms.button button1;<br /> &nbsp;&nbsp;private system.windows.forms.textbox textbox1;<br /> &nbsp;&nbsp;private system.windows.forms.button button2;<br /> &nbsp;&nbsp;private system.windows.forms.button button3;<br /> &nbsp;&nbsp;/// &lt;summary&gt;<br /> &nbsp;&nbsp;/// required designer variable.<br /> &nbsp;&nbsp;/// &lt;/summary&gt;<br /> &nbsp;&nbsp;private system.componentmodel.container components = null;</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;public form1()<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;//<br /> &nbsp;&nbsp;&nbsp;// required for windows form designer support<br /> &nbsp;&nbsp;&nbsp;//<br /> &nbsp;&nbsp;&nbsp;initializecomponent();</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;//<br /> &nbsp;&nbsp;&nbsp;// todo: add any constructor code after initializecomponent call<br /> &nbsp;&nbsp;&nbsp;//<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;/// &lt;summary&gt;<br /> &nbsp;&nbsp;/// clean up any resources being used.<br /> &nbsp;&nbsp;/// &lt;/summary&gt;<br /> &nbsp;&nbsp;protected override void dispose( bool disposing )<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;if( disposing )<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;if (components != null)&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;components.dispose();<br /> &nbsp;&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;base.dispose( disposing );<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;#region windows form designer generated code<br /> &nbsp;&nbsp;/// &lt;summary&gt;<br /> &nbsp;&nbsp;/// required method for designer support - do not modify<br /> &nbsp;&nbsp;/// the contents of this method with the code editor.<br /> &nbsp;&nbsp;/// &lt;/summary&gt;<br /> &nbsp;&nbsp;private void initializecomponent()<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;this.button1 = new system.windows.forms.button();<br /> &nbsp;&nbsp;&nbsp;this.textbox1 = new system.windows.forms.textbox();<br /> &nbsp;&nbsp;&nbsp;this.button2 = new system.windows.forms.button();<br /> &nbsp;&nbsp;&nbsp;this.button3 = new system.windows.forms.button();<br /> &nbsp;&nbsp;&nbsp;this.suspendlayout();<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;// button1<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;this.button1.location = new system.drawing.point(576, 320);<br /> &nbsp;&nbsp;&nbsp;this.button1.name = "button1";<br /> &nbsp;&nbsp;&nbsp;this.button1.size = new system.drawing.size(112, 23);<br /> &nbsp;&nbsp;&nbsp;this.button1.tabindex = 0;<br /> &nbsp;&nbsp;&nbsp;this.button1.text = "savefiletodb";<br /> &nbsp;&nbsp;&nbsp;this.button1.click += new system.eventhandler(this.button1_click);<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;// textbox1<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;this.textbox1.location = new system.drawing.point(0, 0);<br /> &nbsp;&nbsp;&nbsp;this.textbox1.multiline = true;<br /> &nbsp;&nbsp;&nbsp;this.textbox1.name = "textbox1";<br /> &nbsp;&nbsp;&nbsp;this.textbox1.size = new system.drawing.size(568, 424);<br /> &nbsp;&nbsp;&nbsp;this.textbox1.tabindex = 1;<br /> &nbsp;&nbsp;&nbsp;this.textbox1.text = "textbox1";<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;// button2<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;this.button2.location = new system.drawing.point(600, 104);<br /> &nbsp;&nbsp;&nbsp;this.button2.name = "button2";<br /> &nbsp;&nbsp;&nbsp;this.button2.tabindex = 2;<br /> &nbsp;&nbsp;&nbsp;this.button2.text = "readword";<br /> &nbsp;&nbsp;&nbsp;this.button2.click += new system.eventhandler(this.button2_click);<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;// button3<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;this.button3.location = new system.drawing.point(568, 184);<br /> &nbsp;&nbsp;&nbsp;this.button3.name = "button3";<br /> &nbsp;&nbsp;&nbsp;this.button3.size = new system.drawing.size(112, 23);<br /> &nbsp;&nbsp;&nbsp;this.button3.tabindex = 3;<br /> &nbsp;&nbsp;&nbsp;this.button3.text = "readfromdb";<br /> &nbsp;&nbsp;&nbsp;this.button3.click += new system.eventhandler(this.button3_click);<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;// form1<br /> &nbsp;&nbsp;&nbsp;//&nbsp;<br /> &nbsp;&nbsp;&nbsp;this.autoscalebasesize = new system.drawing.size(5, 13);<br /> &nbsp;&nbsp;&nbsp;this.clientsize = new system.drawing.size(712, 429);<br /> &nbsp;&nbsp;&nbsp;this.controls.add(this.button3);<br /> &nbsp;&nbsp;&nbsp;this.controls.add(this.button2);<br /> &nbsp;&nbsp;&nbsp;this.controls.add(this.textbox1);<br /> &nbsp;&nbsp;&nbsp;this.controls.add(this.button1);<br /> &nbsp;&nbsp;&nbsp;this.name = "form1";<br /> &nbsp;&nbsp;&nbsp;this.text = "form1";</span></p>  <p style="line-height:19.5pt;background:white"><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;this.load += new system.eventhandler(this.form1_load);<br /> &nbsp;&nbsp;&nbsp;this.resumelayout(false);</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; "><br /> &nbsp;&nbsp;}<br /> &nbsp;&nbsp;#endregion</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;/// &lt;summary&gt;<br /> &nbsp;&nbsp;/// the main entry point for the application.<br /> &nbsp;&nbsp;/// &lt;/summary&gt;<br /> &nbsp;&nbsp;[stathread]<br /> &nbsp;&nbsp;static void main()&nbsp;<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;application.run(new form1());<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;private void button1_click(object sender, system.eventargs e)//</span><span style="font-size: 9pt; ">把</span><span style="font-size: 9pt; font-family: Simsun, serif; ">word</span><span style="font-size: 9pt; ">存入</span><span style="font-size: 9pt; font-family: Simsun, serif; ">sqlserver<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dbmana dm=new dbmana();<br /> &nbsp;&nbsp;&nbsp;sqlconnection con=dm.getcon();//</span><span style="font-size: 9pt; ">另外的类</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">返回</span><span style="font-size: 9pt; font-family: Simsun, serif; ">sqlserver</span><span style="font-size: 9pt; ">连接</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">用的时候要自己建立连接</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;sqldataadapter comm=new sqldataadapter("select * from myimages",con);<br /> &nbsp;&nbsp;&nbsp;sqlcommandbuilder scb=new sqlcommandbuilder(comm);//</span><span style="font-size: 9pt; ">只有这样才能保证</span><span style="font-size: 9pt; font-family: Simsun, serif; ">dataadapter</span><span style="font-size: 9pt; ">可以</span><span style="font-size: 9pt; font-family: Simsun, serif; ">update<br /> &nbsp;&nbsp;&nbsp;dataset ds=new dataset("myimages");<br /> &nbsp;&nbsp;&nbsp;comm.fill(ds,"myimages");<br /> &nbsp;&nbsp;&nbsp;comm.missingschemaaction=missingschemaaction.addwithkey;<br /> &nbsp;&nbsp;&nbsp;datarow newrow;<br /> &nbsp;&nbsp;&nbsp;newrow=ds.tables[0].newrow();<br /> &nbsp;&nbsp;&nbsp;filestream fs=new filestream(@"e:\club.doc",filemode.open,fileaccess.read);<br /> &nbsp;&nbsp;&nbsp;byte[] data=new byte[fs.length];<br /> &nbsp;&nbsp;&nbsp;fs.read(data,0,convert.toint32(fs.length));//</span><span style="font-size: 9pt; ">文件读到</span><span style="font-size: 9pt; font-family: Simsun, serif; ">byte[]<br /> &nbsp;&nbsp;&nbsp;fs.close();<br /> &nbsp;&nbsp;&nbsp;comm.fill(ds,"myimages");<br /> &nbsp;&nbsp;&nbsp;newrow["id"]=3;<br /> &nbsp;&nbsp;&nbsp;newrow["description"]="this is a file";<br /> &nbsp;&nbsp;&nbsp;newrow["imgfield"]=data;//insert the binary stream<br /> &nbsp;&nbsp;&nbsp;ds.tables["myimages"].rows.add(newrow);<br /> &nbsp;&nbsp;&nbsp;comm.update(ds,"myimages");//update,then the table is update<br /> &nbsp;&nbsp;&nbsp;con.close();</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;/*try<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;con.open();<br /> &nbsp;&nbsp;&nbsp;&nbsp;ds.tables[0].rows[0]["content"]=data;<br /> &nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;catch(exception ex)<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;this.textbox1.text=ex.tostring();</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; "><br /> &nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;finally<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;fs.close();<br /> &nbsp;&nbsp;&nbsp;&nbsp;con.close();</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;}*/</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;private void form1_load(object sender, system.eventargs e)<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;private void button2_click(object sender, system.eventargs e)//read the word file<br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;object nothing=system.reflection.missing.value;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;object&nbsp;<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#102;&#105;&#108;&#101;&#110;&#97;&#109;&#101;&#61;&#64;&#37;&#50;&#50;&#101;&#58;&#47;&#99;&#108;&#117;&#98;&#46;&#100;&#111;&#99;"><span style="color: #333333; ">filename=@"e:\club.doc</span></a>";<br /> &nbsp;&nbsp;&nbsp;word.applicationclass ap=new word.applicationclass();<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;word.document doc=ap.documents.open(ref filename,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing);<br /> &nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;ap.visible=true;<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;<br /> &nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;private void button3_click(object sender, system.eventargs e)//read from table,and</span><span style="font-size: 9pt; ">临时存放</span><span style="font-size: 9pt; font-family: Simsun, serif; ">,</span><span style="font-size: 9pt; ">便于读取然后可以删掉</span><span style="font-size: 9pt; font-family: Simsun, serif; "><br /> &nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;dbmana dm=new dbmana();<br /> &nbsp;&nbsp;sqlconnection con=dm.getcon();<br /> &nbsp;&nbsp;&nbsp;//sqlcommand com=new sqlcommand("select imgfield from myimages",con);<br /> &nbsp;&nbsp;&nbsp;dataset ds=new dataset();<br /> &nbsp;&nbsp;&nbsp;sqldataadapter comm=new sqldataadapter("select imgfield from myimages",con);<br /> &nbsp;&nbsp;&nbsp;sqlcommandbuilder scb=new sqlcommandbuilder(comm);<br /> &nbsp;&nbsp;&nbsp;byte[] data=new byte[0];<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comm.fill(ds,"myimages");<br /> &nbsp;&nbsp;&nbsp;datarow newrow;<br /> &nbsp;&nbsp;&nbsp;newrow=ds.tables["myimages"].rows[3];<br /> &nbsp;&nbsp;&nbsp;data=(byte[])newrow["imgfield"];<br /> &nbsp;&nbsp;&nbsp;int arraysize=new int();//</span><span style="font-size: 9pt; ">注意这句话</span><span style="font-size: 9pt; font-family: Simsun, serif; "><br /> &nbsp;&nbsp;&nbsp;arraysize=data.getupperbound(0);</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;filestream fs=new filestream(@"e:\test.doc",filemode.openorcreate,fileaccess.write);<br /> &nbsp;&nbsp;&nbsp;try<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;&nbsp;fs.write(data,0,arraysize);<br /> &nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;catch(exception ex)<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;this.textbox1.text=ex.tostring();</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;}<br /> &nbsp;&nbsp;&nbsp;finally<br /> &nbsp;&nbsp;&nbsp;{<br /> &nbsp;&nbsp;&nbsp;&nbsp;con.close();<br /> &nbsp;&nbsp;&nbsp;&nbsp;fs.close();<br /> &nbsp;&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;}</span></p>  <p style="line-height: 19.5pt; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: white; background-position: initial initial; background-repeat: initial initial; "><span style="font-size: 9pt; font-family: Simsun, serif; ">&nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;&nbsp;<br /> &nbsp;&nbsp;<br /> &nbsp;&nbsp;}<br /> &nbsp;}</span></p>  <p>&nbsp;</p><img src ="http://www.cnitblog.com/yide/aggbug/77991.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 15:05 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77991.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Fileupload--sqlserver2005</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77990.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 06:54:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77990.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77990.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77990.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77990.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77990.html</trackback:ping><description><![CDATA[<pre id="question-content" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 24px; background-color: #fcfefc; "><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">数据库：Sql Server 2005&nbsp;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">字段：image_file &nbsp; &nbsp; 类型：image</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">前台控件：FileUpLoad（fuImage）、上传button(btnUpload)、查询button、GridVew</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">图片上传代码：</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; protected void btnUpload_Click(object sender, EventArgs e)</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; {</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; byte[] imgBinaryData = this.fuImage.FileBytes;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string sql = "insert into image(image_file) values (@img)";</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string strconn ="Data Source=SMARTGUOLEI;Initial Catalog=web;Persist Security Info=True;User ID=sa;Password=sa;";</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlConnection sqlConn = new SqlConnection(strconn);</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlCommand sqlComm = new SqlCommand(sql, sqlConn);</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlComm.Parameters.Add("@img", SqlDbType.Image);//添加参数</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlComm.Parameters["@img"].Value = imgBinaryData;//为参数赋值</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlConn.Open();</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlComm.ExecuteNonQuery();</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sqlConn.Close();</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script language='javascript'&gt;alert('保存成功！')&lt;/script&gt;");</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">此代码应该是运行正常，因为我通过SqlDataSource控制的配置数据源的功能，在最后完成的那一步，通过查询的功能看到上传上来的图像。</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">数据查询代码：</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">protected void Button1_Click(object sender, EventArgs e)</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; {</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; string s;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; s = "select * from image";</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; OleDbConnection Conn = null;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; DataSet ds = null;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; string strConn = "Data Source=SMARTGUOLEI;Initial Catalog=web;Persist Security Info=True;User ID=sa;Password=sa;Provider=SQLOLEDB.1;";</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; Conn = new OleDbConnection(strConn); //实例化一个连接</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; OleDbCommand Cmd = new OleDbCommand(s);</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; OleDbDataAdapter ODA = new OleDbDataAdapter(Cmd); //实例化一个数据适配器</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; ODA.SelectCommand.Connection = Conn;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; Conn.Open();//记得要打开连接</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; //ODA.SelectCommand.CommandText=s;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; ds = new DataSet();</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; ODA.Fill(ds, "image");</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; this.GridView1.DataSource = ds;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; this.GridView1.DataBind();</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; }</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">此代码应该是运行正常的，因为我在数据库表的设计上，加了一个int编号主键（自动增值 ），在GridView显示时，可以将那个编号查询出来。</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; ">&nbsp;</div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">GridView的前台代码：</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;Columns&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;asp:ImageField DataImageUrlField="image_file"&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/asp:ImageField&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &lt;/Columns&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;">&nbsp; &nbsp; &lt;/asp:GridView&gt;</span></div><div style="font-size: 14px; "><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;"><br /></span></div><div style="font-family: Tahoma; font-size: 11px; "></div></pre><img src ="http://www.cnitblog.com/yide/aggbug/77990.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 14:54 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77990.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>FileUpload--example</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77989.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 06:18:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77989.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77989.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77989.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77989.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77989.html</trackback:ping><description><![CDATA[<p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">在VS2008中，使用&lt;asp:UploadFile控件</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">前台页面</p><div bg_html"="" style="width: 846px; line-height: 26px; text-align: left; "><div><div><strong>[html]</strong>&nbsp;<a href="http://blog.csdn.net/aiouwen521/article/details/6674725#" title="view plain" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_plain.gif); padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">view plain</a><a href="http://blog.csdn.net/aiouwen521/article/details/6674725#" title="copy" style="background-image: url(http://static.blog.csdn.net/scripts/SyntaxHighlighter/styles/images/default/ico_copy.gif); padding-top: 1px; padding-right: 1px; padding-bottom: 1px; padding-left: 1px; display: inline-block; width: 16px; height: 16px; text-indent: -2000px; background-position: 0% 0%; background-repeat: no-repeat no-repeat; ">copy</a><div style="position: absolute; left: 383px; top: 495px; width: 18px; height: 18px; z-index: 99; border-image: initial; "><embed id="ZeroClipboardMovie_1" src="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="18" height="18" name="ZeroClipboardMovie_1" align="center" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&amp;width=18&amp;height=18" wmode="transparent"></div></div></div><ol start="1"><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;</span>%@&nbsp;Page&nbsp;<span style="color: red; ">Language</span>=<span style="color: blue; ">"C#"</span>&nbsp;<span style="color: red; ">AutoEventWireup</span>=<span style="color: blue; ">"true"</span>&nbsp;<span style="color: red; ">CodeBehind</span>=<span style="color: blue; ">"FileUpload.aspx.cs"</span>&nbsp;<span style="color: red; ">Inherits</span>=<span style="color: blue; ">"WebApplication1.FileUpload"</span>&nbsp;%<span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&lt;!DOCTYPE&nbsp;html&nbsp;PUBLIC&nbsp;"-//W3C//DTD&nbsp;XHTML&nbsp;1.0&nbsp;Transitional//EN"&nbsp;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"<span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">html</span>&nbsp;<span style="color: red; ">xmlns</span>=<span style="color: blue; ">"http://www.w3.org/1999/xhtml"</span>&nbsp;<span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">head</span>&nbsp;<span style="color: red; ">runat</span>=<span style="color: blue; ">"server"</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">title</span><span style="color: #993300; font-weight: bold; ">&gt;</span>无标题<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">title</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">script</span>&nbsp;<span style="color: red; ">type</span>=<span style="color: blue; ">"text/javascript"</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;checkType()&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//得到上传文件的值&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;<span style="color: red; ">fileName</span>&nbsp;=&nbsp;<span style="color: blue; ">document</span>.getElementById('FileUpLoad1').value;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//返回String对象中字符串最后出现的位置。&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;<span style="color: red; ">seat</span>&nbsp;=&nbsp;<span style="color: blue; ">fileName</span>.lastIndexOf(".");&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//返回位于String对象中指定位置的子字符串并转换为小写&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;<span style="color: red; ">extension</span>&nbsp;=&nbsp;<span style="color: blue; ">fileName</span>.substring(seat).toLowerCase();&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var&nbsp;<span style="color: red; ">allowed</span>&nbsp;=&nbsp;[".xls",&nbsp;".xlsx"];&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for&nbsp;(var&nbsp;<span style="color: red; ">i</span>&nbsp;=&nbsp;<span style="color: blue; ">0</span>;&nbsp;i&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span>&nbsp;<span style="color: #993300; font-weight: bold; ">allowed.length</span>;&nbsp;i++)&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!(allowed[i]&nbsp;!=&nbsp;extension))&nbsp;{&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;true;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;alert("不支持"&nbsp;+&nbsp;extension&nbsp;+&nbsp;"格式");&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;false;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">script</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">head</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">body</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">form</span>&nbsp;<span style="color: red; ">id</span>=<span style="color: blue; ">"form1"</span>&nbsp;<span style="color: red; ">runat</span>=<span style="color: blue; ">"server"</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">div</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">asp:FileUpload</span>&nbsp;<span style="color: red; ">ID</span>=<span style="color: blue; ">"FileUpLoad1"</span>&nbsp;<span style="color: red; ">runat</span>=<span style="color: blue; ">"server"</span>&nbsp;<span style="color: #993300; font-weight: bold; ">/&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">br</span>&nbsp;<span style="color: #993300; font-weight: bold; ">/&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">asp:Button</span>&nbsp;<span style="color: red; ">ID</span>=<span style="color: blue; ">"btnFileUpload"</span>&nbsp;<span style="color: red; ">runat</span>=<span style="color: blue; ">"server"</span>&nbsp;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">Text</span>=<span style="color: blue; ">"文件上传"</span>&nbsp;<span style="color: red; ">OnClientClick</span>=<span style="color: blue; ">"return&nbsp;checkType()"</span>&nbsp;&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">onclick</span>=<span style="color: blue; ">"btnFileUpload_Click"</span>&nbsp;<span style="color: #993300; font-weight: bold; ">/&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;</span><span style="color: #993300; font-weight: bold; ">asp:Label</span>&nbsp;<span style="color: red; ">ID</span>=<span style="color: blue; ">"lblMessage"</span>&nbsp;<span style="color: red; ">runat</span>=<span style="color: blue; ">"server"</span><span style="color: #993300; font-weight: bold; ">&gt;</span><span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">asp:Label</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">div</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">form</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">body</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li><li style="border-width: initial; border-color: initial; line-height: 18px; "><span style="color: #993300; font-weight: bold; ">&lt;/</span><span style="color: #993300; font-weight: bold; ">html</span><span style="color: #993300; font-weight: bold; ">&gt;</span>&nbsp;&nbsp;</li></ol></div><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; "><br />&nbsp;</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">后台代码：</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">using System;<br />using System.Collections.Generic;<br />using System.Linq;<br />using System.Web;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.Data.OleDb;<br />using System.Data;</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">namespace WebApplication1<br />{<br />&nbsp;&nbsp;&nbsp; public partial class FileUpload : System.Web.UI.Page<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void Page_Load(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; protected void btnFileUpload_Click(object sender, EventArgs e)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpLoad1.HasFile)<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; //判断文件是否小于4MB<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (FileUpLoad1.PostedFile.ContentLength &lt; 4194304)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HttpPostedFile file = FileUpLoad1.PostedFile;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string str=file.FileName;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string filename2 = str.Substring(str.LastIndexOf(".")).ToString().Trim();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string filename1 = DateTime.Now.Ticks.ToString()+filename2;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; file.SaveAs(Server.MapPath("./upload/"+filename1));//将用户上传的文件保存到服务器上.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("./upload/"+filename1) + ";Extended Properties=\"Excel 8.0;HDR=YES;IMEX=1\"";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OleDbConnection Oleconn = new OleDbConnection(strConn);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; string strExcel = "";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OleDbDataAdapter excelCommand = null;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; DataSet excel_ds = new DataSet();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strExcel = "select * from [sheet1$]";<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<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; Oleconn.Open();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; excelCommand = new OleDbDataAdapter(strExcel, Oleconn);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; excelCommand.Fill(excel_ds, "exdtSource");//得到dataset<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lblMessage.Text = "上传成功!";<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; catch (Exception ex)<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; lblMessage.Text = "出现异常，无法上传!";<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; finally<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; Oleconn.Close();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Oleconn.Dispose();<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p style="padding-top: 0px; padding-bottom: 0px; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&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; else<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; lblMessage.Text = "上传文件不能大于10MB!";<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;&nbsp;&nbsp; else<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; lblMessage.Text = "尚未选择文件!";<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;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; }<br />}</p><img src ="http://www.cnitblog.com/yide/aggbug/77989.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 14:18 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77989.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>文件上传-下载</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77986.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 05:17:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77986.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77986.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77986.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77986.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">文件的上传下载是我们在实际项目开发过程中经常需要用到的技术，这里给出几种常见的方法，本文主要内容包括：<br /><br />1、如何解决文件上传大小的限制<br /><br />2、以文件形式保存到服务器<br /><br />3、转换成二进制字节流保存到数据库以及下载方法<br /><br />4、上传Internet上的资源&nbsp;<br /><br />第一部分：<br /><br />首先我们来说一下如何解决ASP.NET中的文件上传大小限制的问题，我们知道在默认情况下ASP.NET的文件上传大小限制为2M，一般情况下，我们可以采用更改WEB.Config文件&nbsp;&lt;system.web&gt;&nbsp;&lt;/system.web&gt;中&nbsp;自定义最大文件大小，如下：<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;httpRuntime executionTimeout="600" maxRequestLength="951200" useFullyQualifiedRedirectUrl="true" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/&gt;这样上传文件的最大值就变成了4M，但这样并不能让我们无限的扩大 MaxRequestLength的值，因为ASP.NET会将全部文件载入内存后，再加以处理。解决的方法是利用隐含的 HttpWorkerRequest，用它的GetPreloadedEntityBody和ReadEntityBody方法从IIS为ASP.NET 建立的pipe里分块读取数据。实现方法如下：<br /><br /></p><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody><tr><td>IServiceProviderprovider=(IServiceProvider)HttpContext.Current;<br />HttpWorkerRequestwr=(HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));<br />byte[]bs=wr.GetPreloadedEntityBody();<br />.<br />if(!wr.IsEntireEntityBodyIsPreloaded())<br />{<br />intn=1024;<br />byte[]bs2=newbyte[n];<br />while(wr.ReadEntityBody(bs2,n)&gt;0)<br />{<br />..<br />}<br />}</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">这样就可以解决了大文件的上传问题了。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">第二部分：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">下面我们来介绍如何以文件形式将客户端的一个文件上传到服务器并返回上传文件的一些基本信息。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">首先我们定义一个类，用来存储上传的文件的信息（返回时需要）。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody><tr><td>public class FileUpLoad<br />{<br />public FileUpLoad()<br />{}<br />/**//// &lt;summary&gt;<br />/// 上传文件名称<br />/// &lt;/summary&gt;<br />public string FileName<br />{<br />get<br />{<br />return fileName;<br />}<br />set<br />{<br />fileName = value;<br />}<br />}<br />private string fileName;<br /><br />/**//// &lt;summary&gt;<br />/// 上传文件路径<br />/// &lt;/summary&gt;<br />public string FilePath<br />{<br />get<br />{<br />return filepath;<br />}<br />set<br />{<br />filepath = value;<br />}<br />}<br />private string filepath;<br /><br />/**//// &lt;summary&gt;<br />/// 文件扩展名<br />/// &lt;/summary&gt;<br />public string FileExtension<br />{<br />get<br />{<br />return fileExtension;<br />}<br />set<br />{<br />fileExtension = value;<br />}<br />}<br />private string fileExtension;<br />}</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">另外我们还可以在配置文件中限制上传文件的格式(App.Config)：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" data-find="_3" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody data-find="_2"><tr data-find="_1"><td>&lt;?xml version="1.0" encoding="gb2312" ?&gt;<br />&lt;Application&gt;&nbsp;<br />&lt;FileUpLoad&gt;<br />&lt;Format&gt;.jpg|.gif|.png|.bmp&lt;/Format&gt;<br />&lt;/FileUpLoad&gt;<br />&lt;/Application&gt;<br /><br />这样我们就可以开始写我们的上传文件的方法了，如下：<br /><br />public FileUpLoad UpLoadFile(HtmlInputFile InputFile,string filePath,string myfileName,bool isRandom)<br />{<br />FileUpLoad fp = new FileUpLoad();<br />string fileName,fileExtension;<br />string saveName;<br /><br />//<br />//建立上传对象<br />//<br />HttpPostedFile postedFile = InputFile.PostedFile;<br /><br />fileName = System.IO.Path.GetFileName(postedFile.FileName);<br />fileExtension = System.IO.Path.GetExtension(fileName);<br /><br />//<br />//根据类型确定文件格式<br />//<br />AppConfig app = new AppConfig();<br />string format = app.GetPath("FileUpLoad/Format");<br /><br />//<br />//如果格式都不符合则返回<br />//<br />if(format.IndexOf(fileExtension)==-1)<br />{<br />throw new ApplicationException("上传数据格式不合法");<br />}<br /><br />//<br />//根据日期和随机数生成随机的文件名<br />//<br />if(myfileName != string.Empty)<br />{<br />fileName = myfileName;&nbsp;<br />}<br /><br />if(isRandom)<br />{<br />Random objRand = new Random();<br />System.DateTime date = DateTime.Now;<br />//生成随机文件名<br />saveName = date.Year.ToString() + date.Month.ToString() + date.Day.ToString() + date.Hour.ToString() + date.Minute.ToString() + date.Second.ToString() + Convert.ToString(objRand.Next(99)*97 + 100);<br />fileName = saveName + fileExtension;<br />}<br /><br />string phyPath = HttpContext.Current.Request.MapPath(filePath);<br /><br />//判断路径是否存在,若不存在则创建路径<br />DirectoryInfo upDir = new DirectoryInfo(phyPath);<br />if(!upDir.Exists)<br />{<br />upDir.Create();<br />}<br /><br />//<br />//保存文件<br />//<br />try<br />{<br />postedFile.SaveAs(phyPath + fileName);<br /><br />fp.FilePath = filePath + fileName;<br />fp.FileExtension = fileExtension;<br />fp.FileName = fileName;<br />}<br />catch<br />{<br />throw new ApplicationException("上传失败!");<br />}<br /><br />//返回上传文件的信息<br />return fp;<br />}</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">然后我们在上传文件的时候就可以调用这个方法了，将返回的文件信息保存到数据库中，至于下载，就直接打开那个路径就OK了。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">第三部分：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">这里我们主要说一下如何以二进制的形式上传文件以及下载。首先说上传，方法如下：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody><tr><td>public byte[] UpLoadFile(HtmlInputFile f_IFile)<br />{<br />//获取由客户端指定的上传文件的访问<br />HttpPostedFile upFile=f_IFile.PostedFile;<br />//得到上传文件的长度<br />int upFileLength=upFile.ContentLength;&nbsp;<br />//得到上传文件的客户端MIME类型<br />string contentType = upFile.ContentType;<br />byte[] FileArray=new Byte[upFileLength];<br /><br />Stream fileStream=upFile.InputStream;&nbsp;<br /><br />fileStream.Read(FileArray,0,upFileLength);<br />return FileArray;<br />}</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">这个方法返回的就是上传的文件的二进制字节流，这样我们就可以将它保存到数据库了。下面说一下这种形式的下载，也许你会想到这种方式的下载就是新建一 个aspx页面，然后在它的Page_Load()事件里取出二进制字节流，然后再读出来就可以了，其实这种方法是不可取的，在实际的运用中也许会出现无 法打开某站点的错误，我一般采用下面的方法：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">首先，在Web.config中加入：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody><tr><td>&lt;add verb="*" path="openfile.aspx" type="RuixinOA.Web.BaseClass.OpenFile, RuixinOA.Web"/&gt;</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">这表示我打开openfile.aspx这个页面时，系统就会自动转到执行RuixinOA.Web.BaseClass.OpenFile 这个类里的方法，具体实现如下：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" data-find="_14" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody data-find="_13"><tr data-find="_12"><td>using System;<br />using System.Data;<br />using System.Web;<br />using System.IO;<br />using Ruixin.WorkFlowDB;<br />using RXSuite.Base;<br />using RXSuite.Component;<br />using RuixinOA.BusinessFacade;<br /><br />namespace RuixinOA.Web.BaseClass<br />{<br />/**//// &lt;summary&gt;<br />/// NetUFile 的摘要说明。<br />/// &lt;/summary&gt;<br />public class OpenFile : IHttpHandler<br />{<br />public void ProcessRequest(HttpContext context)&nbsp;<br />{<br />//从数据库中取出要下载的文件信息<br />RuixinOA.BusinessFacade.RX_OA_FileManager os = new RX_OA_FileManager();<br />EntityData data = os.GetFileDetail(id);<br /><br />if(data != null &amp;&amp; data.Tables["RX_OA_File"].Rows.Count &gt; 0)<br />{<br />DataRow dr = (DataRow)data.Tables["RX_OA_File"].Rows[0];<br />context.Response.Buffer = true;<br />context.Response.Clear();<br />context.Response.ContentType = dr["CContentType"].ToString();&nbsp;<br />context.Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(dr["CTitle"].ToString()));<br />context.Response.BinaryWrite((Byte[])dr["CContent"]);<br />context.Response.Flush();<br />context.Response.End();<br />}<br />}<br />public bool IsReusable&nbsp;<br />{ 　<br />get { return true;}&nbsp;<br />}<br />}<br />}</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">执行上面的方法后，系统会提示用户选择直接打开还是下载。这一部分我们就说到这里。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">第四部分：</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">这一部分主要说如何上传一个Internet上的资源到服务器。</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">首先需要引用 System.Net 这个命名空间，然后操作如下：&nbsp;</span><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><table border="1" align="center" bgcolor="#e3e3e3" bordercolor="#cccccc" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; width: 622px; "><tbody><tr><td>HttpWebRequest hwq = (HttpWebRequest)WebRequest.Create("http://localhost/pwtest/webform1.aspx");<br />HttpWebResponse hwr = (HttpWebResponse)hwq.GetResponse();<br />byte[] bytes = new byte[hwr.ContentLength];<br />Stream stream = hwr.GetResponseStream();<br />stream.Read(bytes,0,Convert.ToInt32(hwr.ContentLength));<br />//HttpContext.Current.Response.BinaryWrite(bytes);</td></tr></tbody></table><br style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; " /><span style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">HttpWebRequest 可以从Internet上读取文件，因此可以很好的解决这个问题。</span><img src ="http://www.cnitblog.com/yide/aggbug/77986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 13:17 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>WebPage--上传下载</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77985.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 03:52:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77985.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77985.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77985.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77985.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77985.html</trackback:ping><description><![CDATA[<pre id="best-answer-content"  mb10"="" style="margin-top: 0px; margin-bottom: 10px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: Arial; white-space: pre-wrap; word-wrap: break-word; zoom: 1; line-height: 22px; font-size: 14px; background-color: #fffcf6; "><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //数据检查 begin</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string schType = string.Empty;//学校类型</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string gradeName = string.Empty;// 年级名称</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string subjectName = string.Empty;//科目名称 &nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string videoName = this.txtName.Text.Trim();//视频名称</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string imgTrueName = string.Empty;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; schType = this.ddlSchool.SelectedValue.ToString().Trim();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; gradeName=this.ddlGrade.SelectedValue.ToString().Trim();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; subjectName = this.txtSubject.Text.Trim();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; videoName = this.txtName.Text.Trim();</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (schType == "请选择" || gradeName == "请选择")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请选择学校类型和年级！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (subjectName=="")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请输入视频对应的科目！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (videoName == "")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请输入视频的名称！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((this.fudFile.PostedFile.FileName == null) || (this.fudFile.PostedFile.FileName == ""))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请选择需上传的视频文件！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((this.fudImg.PostedFile.FileName == null) || (this.fudImg.PostedFile.FileName == ""))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请选择需上传的图片文件！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileInfo fileTag = new FileInfo(this.fudFile.PostedFile.FileName);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string fileType = fileTag.Extension;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string fileName=fileTag.Name;// 文件物理名称</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (fileType.ToLower() != ".flv")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请确保您选择的是flv文件！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileInfo imgFileTag = new FileInfo(this.fudImg.PostedFile.FileName);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string imgFileType = imgFileTag.Extension;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (imgFileType.ToLower() != ".jpg" &amp;&amp; imgFileType.ToLower() != ".bmp" &amp;&amp; imgFileType.ToLower() != ".jpeg" &amp;&amp; imgFileType.ToLower() != ".gif" &amp;&amp; imgFileType.ToLower() != ".png")</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('请确保您选择的是图片文件！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //数据检查 end</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //string physicalPath = this.Page.MapPath(@"./UploadFileFolder");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string physicalPath = Server.MapPath("\\images\\UploadExperimentVideos").ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string imgPhysicalPath = Server.MapPath("\\images\\VideoImages").ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DateTime uploadTime = DateTime.Now;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string year = DateTime.Now.Year.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string month = DateTime.Now.Month.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string date = DateTime.Now.Day.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string hour = DateTime.Now.Hour.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string minute = DateTime.Now.Minute.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string second = DateTime.Now.Second.ToString();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string fileTrueName ="video"+ year + month + date + hour + minute + second + fileType;//文件绝对名称</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string imgFileTrueName = "img" + year + month + date + hour + minute + second + imgFileType;//图片绝对名称</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string path_fileName = physicalPath + "/" + fileTrueName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string path_imgFileName = imgPhysicalPath + "/" + imgFileTrueName;</span></div><div><span style="font-size: 12px;"><br /></span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (File.Exists(path_fileName))</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; File.Delete(path_fileName);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SqlParameter[] spl ={</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@schType",SqlDbType.VarChar,50),&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@gradeName",SqlDbType.VarChar,50),&nbsp;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@subjectName",SqlDbType.VarChar,250),</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@videoTrueName",SqlDbType.VarChar,250),</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@videoName",SqlDbType.VarChar,250),</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@imgTrueName",SqlDbType.VarChar,250),</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new SqlParameter("@ret",SqlDbType.Int,4)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; };</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[0].Value = schType;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[1].Value = gradeName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[2].Value = subjectName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[3].Value = fileTrueName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[4].Value = videoName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[5].Value = imgFileTrueName;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spl[6].Direction = ParameterDirection.Output;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dbhelper.SQLHelper.GetDataTable("SQLCont", CommandType.StoredProcedure, spl);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int ret=Convert.ToInt32(spl[6].Value.ToString());</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (ret == 1)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fudFile.PostedFile.SaveAs(path_fileName);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fudImg.PostedFile.SaveAs(path_imgFileName);</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BindData();</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('视频上传成功！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (ret == 3)</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('视频上传重复！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Response.Write("&lt;script&gt;alert('视频上传失败！');&lt;/script&gt;");</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;</span></div><div><span style="font-size: 12px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span></div><div><span style="font-size: 12px;">\\按你的需求做适当修改</span></div></pre><img src ="http://www.cnitblog.com/yide/aggbug/77985.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 11:52 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77985.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>c# arrayList遍历</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77984.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 02:28:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77984.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77984.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77984.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77984.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77984.html</trackback:ping><description><![CDATA[<h3>1、ArrayList定义</h3> <p>System.Collections.ArrayList类是一个特殊的数组(即动态数组)。</p> <p>通过添加和删除元素，就可以动态改变数组的长度。</p> <h3>........................<br /><br />详见网址：<a href="http://dalaoyer.com/article.php?id=377" title="http://dalaoyer.com/article.php?id=377">http://dalaoyer.com/article.php?id=377</a></h3><img src ="http://www.cnitblog.com/yide/aggbug/77984.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 10:28 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77984.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C# ArrayList的用法 </title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77982.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 01:59:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77982.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77982.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77982.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77982.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77982.html</trackback:ping><description><![CDATA[<div id="appShareTitle" style="word-wrap: break-word; height: 24px; line-height: 24px; font-size: 14px; font-weight: bold; color: #333333; font-family: arial; background-color: #f4f8fb; "></div><div id="appShareOpt" style="word-wrap: break-word; text-align: right; margin-bottom: 10px; margin-right: 5px; line-height: 24px; font-family: arial; font-size: 14px; background-color: #f4f8fb; "></div><div id="app-share-content" style="word-wrap: break-word; border-top-color: #edf1f4; border-right-color: #edf1f4; border-bottom-color: #edf1f4; border-left-color: #edf1f4; border-image: initial; background-color: #f4f8fb; padding-top: 20px; padding-right: 20px; padding-bottom: 20px; padding-left: 20px; color: #9a9a9a; font-family: arial; "><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">System.Collections.ArrayList类是一个特殊的数组。通过添加和删除元素，就可以动态改变数组的长度。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">一、优点</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">1. 支持自动改变大小的功能</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">2. 可以灵活的插入元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">3. 可以灵活的删除元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">4. 可以灵活访问元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">二、局限性</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">跟一般的数组比起来，速度上差些</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">三、添加元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">1．public virtual int Add(object value);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">将对象添加到ArrayList的结尾处</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">内容为abcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">2．public virtual void Insert(int index,object value);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">将元素插入ArrayList的指定索引处</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Insert(0,"aa");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为aaabcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">3．public virtual void InsertRange(int index,ICollectionc);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">将集合中的某个元素插入ArrayList的指定索引处</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList list2=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">list2.Add("tt");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">list2.Add("ttt");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.InsertRange(2,list2);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为abtttttcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">四、删除</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">a)public virtual void Remove(object obj);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">从ArrayList中移除特定对象的第一个匹配项,注意是第一个</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Remove("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为bcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">2.public virtual void RemoveAt(intindex);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">移除ArrayList的指定索引处的元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.RemoveAt(0);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为bcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">3．public virtual void RemoveRange(int index,int count);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">从ArrayList中移除一定范围的元素。Index表示索引，count表示从索引处开始的数目</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.RemoveRange(1,3);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为ae</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">4．public virtual void Clear();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">从ArrayList中移除所有元素。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">五、排序</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">a)public virtual void Sort();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">对ArrayList或它的一部分中的元素进行排序。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayListaList=newArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataSource=aList;//DropDown ListDropDownList1;</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataBind();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为eabcd</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Sort();//排序</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataSource=aList;//DropDownListDropDownList1;</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataBind();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为abcde</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">b)public virtual void Reverse();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">将ArrayList或它的一部分中元素的顺序反转。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Reverse();//反转</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataSource=aList;//DropDownListDropDownList1;</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">DropDownList1.DataBind();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为edcba</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">六、查找</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">a)public virtual int IndexOf(object);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">b)public virtual int IndexOf(object,int);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">c)public virtual int IndexOf(object,int,int);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">返回ArrayList或它的一部分中某个值的第一个匹配项的从零开始的索引。没找到返回-1。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">intnIndex=aList.IndexOf(&#8220;a&#8221;);//1</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">nIndex=aList.IndexOf(&#8220;p&#8221;);//没找到，-1</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">d)public virtual int LastIndexOf(object);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">e)public virtual int LastIndexOf(object,int);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">f)public virtual int LastIndexOf(object,int,int);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">返回ArrayList或它的一部分中某个值的最后一个匹配项的从零开始的索引。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");//同0</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">intnIndex=aList.LastIndexOf("a");//值为2而不是0</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">g)public virtual bool Contains(objectitem);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">确定某个元素是否在ArrayList中。包含返回true,否则返回false</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">七、获取数组中的元素</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">下面以整数为例，给出获取某个元素的值的方法</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">for(int i=0;i&lt;10;i++)</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">&nbsp;&nbsp;&nbsp;&nbsp; aList.Add(i);</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">for(i=0;i&lt;10;i++)</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">&nbsp;&nbsp;&nbsp; Textbox1.text+=(int)aList[i]+" ";//获取的方式基本与一般的数组相同，使用下标的方式进行</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">结果为：0 1 2 3 4 5 6 7 8 9</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">八、其他</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">1．public virtual intCapacity{get;set;}</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">获取或设置ArrayList可包含的元素数。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">2．public virtual intCount{get;}</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">获取ArrayList中实际包含的元素数。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">Capacity是ArrayList可以存储的元素数。Count是ArrayList中实际包含的元素数。Capacity总是大于或等于Count。如果在添加元素时，Count超过Capacity，则该列表的容量会通过自动重新分配内部数组加倍。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">如果Capacity的值显式设置，则内部数组也需要重新分配以容纳指定的容量。如果Capacity被显式设置为0，则公共语言运行库将其设置为默认容量。默认容量为16。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">在调用Clear后，Count为0，而此时Capacity切是默认容量16，而不是0</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">3．public virtual void TrimToSize();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">将容量设置为ArrayList中元素的实际数量。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">如果不向列表中添加新元素，则此方法可用于最小化列表的内存系统开销。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">若要完全清除列表中的所有元素，请在调用TrimToSize之前调用Clear方法。截去空ArrayList会将ArrayList的容量设置为默认容量，而不是零。</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">ArrayList aList=new ArrayList();</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("a");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("b");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("c");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("d");</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.Add("e");//Count=5,Capacity=16,</p><p style="margin-bottom: 1em; padding-top: 0px; padding-bottom: 0px; color: #6d6d6d; line-height: 26px; text-indent: 2em; ">aList.TrimToSize();//Count=Capacity=5;</p></div><img src ="http://www.cnitblog.com/yide/aggbug/77982.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2012-03-08 09:59 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77982.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>