﻿<?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/1876.html</link><description /><language>zh-cn</language><lastBuildDate>Fri, 13 Nov 2020 03:33:34 GMT</lastBuildDate><pubDate>Fri, 13 Nov 2020 03:33:34 GMT</pubDate><ttl>60</ttl><item><title>sqlserver查阻塞</title><link>http://www.cnitblog.com/yide/archive/2020/11/13/92361.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 13 Nov 2020 03:14:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/11/13/92361.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92361.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/11/13/92361.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92361.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92361.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border-color: #cccccc; border-image: initial; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->查询当前正在执行的语句<br /><br />复制代码<br />SELECT&nbsp;<br />der.[session_id],der.[blocking_session_id],&nbsp;<br />sp.lastwaittype,sp.hostname,sp.program_name,sp.loginame,&nbsp;<br />der.[start_time]&nbsp;AS&nbsp;'开始时间',&nbsp;<br />der.[status]&nbsp;AS&nbsp;'状态',&nbsp;<br />dest.[text]&nbsp;AS&nbsp;'sql语句',&nbsp;<br />DB_NAME(der.[database_id])&nbsp;AS&nbsp;'数据库名',&nbsp;<br />der.[wait_type]&nbsp;AS&nbsp;'等待资源类型',&nbsp;<br />der.[wait_time]&nbsp;AS&nbsp;'等待时间',&nbsp;<br />der.[wait_resource]&nbsp;AS&nbsp;'等待的资源',&nbsp;<br />der.[logical_reads]&nbsp;AS&nbsp;'逻辑读次数'&nbsp;<br />FROM&nbsp;sys.[dm_exec_requests]&nbsp;AS&nbsp;der&nbsp;<br />INNER&nbsp;JOIN&nbsp;master.dbo.sysprocesses&nbsp;AS&nbsp;sp&nbsp;ON&nbsp;der.session_id=sp.spid&nbsp;<br />CROSS&nbsp;APPLY&nbsp;sys.[dm_exec_sql_text](der.[sql_handle])&nbsp;AS&nbsp;dest&nbsp;<br />--WHERE&nbsp;[session_id]&gt;50&nbsp;AND&nbsp;session_id&lt;&gt;@@SPID&nbsp;<br />ORDER&nbsp;BY&nbsp;der.[session_id]&nbsp;<br />GO<br />复制代码<br />&nbsp;<br /><br /><br />是否堵塞<br /><br />SELECT&nbsp;spid,blocked,waittime,waittype,waitresource,p.dbid,cpu,physical_io,memusage,open_tran&nbsp;<br />,status,login_time,last_batch,hostname,program_name,hostprocess,loginame,cmd,text&nbsp;<br />FROM&nbsp;master.dbo.sysprocesses&nbsp;p&nbsp;CROSS&nbsp;APPLY&nbsp;sys.dm_exec_sql_text(p.sql_handle)&nbsp;s&nbsp;<br />WHERE&nbsp;blocked&nbsp;&gt;&nbsp;0&nbsp;OR&nbsp;spid&nbsp;IN(SELECT&nbsp;blocked&nbsp;FROM&nbsp;master.dbo.sysprocesses&nbsp;WHERE&nbsp;blocked&nbsp;&gt;&nbsp;0)&nbsp;<br />go<br />&nbsp;检查锁表<br /><br />select&nbsp;&nbsp;&nbsp;request_session_id&nbsp;&nbsp;&nbsp;spid,OBJECT_NAME(resource_associated_entity_id)&nbsp;tableName<br />from&nbsp;&nbsp;&nbsp;sys.dm_tran_locks&nbsp;t&nbsp;where&nbsp;resource_type='OBJECT'&nbsp;order&nbsp;by&nbsp;spid&nbsp;asc;<br />查询导致死锁的sql语句<br /><br />dbcc&nbsp;inputbuffer(spid);<br />解锁<br /><br />declare&nbsp;@spid&nbsp;&nbsp;<span style="color: #0000FF; ">int</span>&nbsp;<br />Set&nbsp;@spid&nbsp;&nbsp;=&nbsp;123--锁表进程<br />declare&nbsp;@sql&nbsp;varchar(1000)<br /><span style="color: #0000FF; ">set</span>&nbsp;@sql='kill&nbsp;'+cast(@spid&nbsp;&nbsp;<span style="color: #0000FF; ">as</span>&nbsp;varchar)<br />exec(@sql)<br />杀掉进程<br /><br />kill&nbsp;spid</div><img src ="http://www.cnitblog.com/yide/aggbug/92361.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-11-13 11:14 <a href="http://www.cnitblog.com/yide/archive/2020/11/13/92361.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>sql2008删除log</title><link>http://www.cnitblog.com/yide/archive/2020/10/31/92352.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Sat, 31 Oct 2020 12:14:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/10/31/92352.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92352.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/10/31/92352.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92352.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92352.html</trackback:ping><description><![CDATA[<div style="background-color: #eeeeee; font-size: 13px; border-color: #cccccc; border-image: initial; padding: 4px 5px 4px 4px; width: 98%; word-break: break-all;"><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->USE[master]<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br />&nbsp;&nbsp;&nbsp;&nbsp;ALTER&nbsp;DATABASE&nbsp;mydbname&nbsp;SET&nbsp;RECOVERY&nbsp;SIMPLE&nbsp;WITH&nbsp;NO_WAIT<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br />&nbsp;&nbsp;&nbsp;&nbsp;ALTER&nbsp;DATABASE&nbsp;mydbname&nbsp;SET&nbsp;RECOVERY&nbsp;SIMPLE&nbsp;&nbsp;&nbsp;--简单模式<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br />&nbsp;&nbsp;&nbsp;&nbsp;USE&nbsp;mydbname&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br />&nbsp;&nbsp;&nbsp;&nbsp;DBCC&nbsp;SHRINKFILE&nbsp;(N'mydbname_Log'&nbsp;,&nbsp;11,&nbsp;TRUNCATEONLY)<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br />&nbsp;&nbsp;&nbsp;&nbsp;USE[master]<br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;ALTER&nbsp;DATABASE&nbsp;mydbname&nbsp;SET&nbsp;RECOVERY&nbsp;FULL&nbsp;WITH&nbsp;NO_WAIT<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;GO<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;ALTER&nbsp;DATABASE&nbsp;mydbname&nbsp;SET&nbsp;RECOVERY&nbsp;FULL&nbsp;&nbsp;--还原为完全模式<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;GO</div><img src ="http://www.cnitblog.com/yide/aggbug/92352.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-10-31 20:14 <a href="http://www.cnitblog.com/yide/archive/2020/10/31/92352.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Excel VBA 连接数据库操作excel</title><link>http://www.cnitblog.com/yide/archive/2020/05/25/92205.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Mon, 25 May 2020 01:42:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/05/25/92205.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92205.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/05/25/92205.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92205.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92205.html</trackback:ping><description><![CDATA[<div><div>Excel VBA 连接数据库操作excel</div></div><div></div><div>1.连接数据库，查询数据</div><div></div><div>Private Sub CommandButton1_Click()</div><div></div><div>'</div><div>'Dim conn As ADODB.Connection</div><div>'Set conn = New ADODB.Connection</div><div>'</div><div>'&nbsp; &nbsp; Dim rs As ADODB.Recordset</div><div>'</div><div>'&nbsp; &nbsp; Set rs = New ADODB.Recordset</div><div>&nbsp;</div><div>'conn.ConnectionString = "Provider=SQLOLEDB;Server=192.168.*.*;Database=testdb;Uid=sa;Pwd=*****"</div><div>'conn.Open</div><div></div><div>'MsgBox ("连接成功！" &amp; vbCrLf &amp; "数据库状态：" &amp; conn.State &amp; vbCrLf &amp; "数据库版本：" &amp; conn.Version)</div><div>' MsgBox ("连接成功！" &amp; conn.State)</div><div></div><div>'&nbsp; rs.Open "select id,name from table ", conn</div><div>'</div><div>'指定页面单元格赋值</div><div>' Sheet3.Range("A1:B1").Value = Array("id77777", "caption88888")</div><div>'</div><div>'设置表头</div><div>'&nbsp; &nbsp; Range("A1:B1").Value = Array("id", "name")</div><div>''将数据输出到工作表</div><div>'&nbsp; &nbsp; Range("A2").CopyFromRecordset rs</div><div>''关闭连接</div><div>'&nbsp; &nbsp; rs.Close: Set rs = Nothing</div><div>'&nbsp; &nbsp; conn.Close: Set conn = Nothing</div><div></div><div></div><div>End Sub</div><div></div><div>2.单元格取值赋值</div><div>Private Sub CommandButton2_Click()</div><div>'指定页面单元格取值</div><div>'&nbsp; &nbsp;MsgBox Sheet3.Range("A3").Value</div><div>'指定页面单元格赋值</div><div>' Sheet3.Range("A1:B1").Value = 43434343</div><div>End Sub</div><div></div><div>******************************************************</div><div></div><div>3.单元格选中单击事件，获取指定行指定列</div><div>Private Sub Worksheet_SelectionChange(ByVal Target As Range)</div><div></div><div></div><div>'MsgBox "777888999"</div><div></div><div>获取指定行指定列</div><div>'If Target.Column = 3 And Target.Row = 5 Then</div><div></div><div>'If Target.Column = 3 Then</div><div></div><div>'&nbsp; MsgBox "你选中了:" &amp; Target.Text &amp; "行:" &amp; Target.Row</div><div>&nbsp;' End If</div><div></div><div></div><div>'End Sub</div><div></div><div>***************************************************8</div><div></div><div>' Private Sub Worksheet_SelectionChange(ByVal Target As Range)</div><div></div><div></div><div>'&nbsp; If Target.Column = 1 And Target.Row = 1 Then</div><div>'&nbsp; MsgBox "你选中了:" &amp; Target.Text</div><div>'&nbsp; End If</div><div>&nbsp;' If Target.Column = 3 And Target.Row = 5 Then</div><div>'&nbsp; MsgBox "你选中了:" &amp; Target.Text</div><div>&nbsp;' End If</div><div>&nbsp;' End Sub</div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><img src ="http://www.cnitblog.com/yide/aggbug/92205.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-05-25 09:42 <a href="http://www.cnitblog.com/yide/archive/2020/05/25/92205.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>将select 查询结果拼接成字串</title><link>http://www.cnitblog.com/yide/archive/2020/05/21/92190.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 21 May 2020 06:57:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/05/21/92190.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92190.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/05/21/92190.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92190.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92190.html</trackback:ping><description><![CDATA[<div>将select 查询结果拼接成字串</div><code keyword"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">select</code>&nbsp;<code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">(</code><code keyword"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">select</code>&nbsp;<code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">id+</code><code string"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">''</code><code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">,name+</code><code string"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">','</code>&nbsp;<code keyword"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">from</code>&nbsp;<code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">table1&nbsp;</code><code keyword"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">for</code>&nbsp;<code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">xml path(</code><code string"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important; color: #0000ff !important;">''</code><code plain"="" style="font-size: 12px; white-space: nowrap; margin: 0px !important; padding: 0px !important; border-radius: 0px !important; background-image: none !important; background-position: initial !important; background-size: initial !important; background-repeat: initial !important; background-attachment: initial !important; background-origin: initial !important; background-clip: initial !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.8em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, &quot;Bitstream Vera Sans Mono&quot;, &quot;Courier New&quot;, Courier, monospace !important; min-height: auto !important;">))</code><br /><br /><img src ="http://www.cnitblog.com/yide/aggbug/92190.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-05-21 14:57 <a href="http://www.cnitblog.com/yide/archive/2020/05/21/92190.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>update table select 值</title><link>http://www.cnitblog.com/yide/archive/2020/05/19/92186.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 19 May 2020 06:42:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/05/19/92186.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92186.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/05/19/92186.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92186.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92186.html</trackback:ping><description><![CDATA[<p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">QL update select语句</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">最常用的update语法是：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE <span style="margin: 0px; padding: 0px;">TABLE_NAME <span style="margin: 0px; padding: 0px;">SET column_name1 <span style="margin: 0px; padding: 0px; color: #66cc66;">= <span style="margin: 0px; padding: 0px; color: #993333;">VALUE WHRER column_name2 <span style="margin: 0px; padding: 0px; color: #66cc66;">= <span style="margin: 0px; padding: 0px; color: #993333;">VALUE</span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">如果我的更新值Value是从一条select语句拿出来，而且有很多列的话，用这种语法就很麻烦</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">第一，要select出来放在临时变量上，有很多个很难保存。 第二，再将变量进行赋值。</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">列多起来非常麻烦，能不能像Insert那样，把整个Select语句的结果进行插入呢？ 就好象下面:：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 3 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">INSERT <span style="margin: 0px; padding: 0px;">INTO table1 <span style="margin: 0px; padding: 0px; color: #66cc66;">(c1<span style="margin: 0px; padding: 0px;">, c2<span style="margin: 0px; padding: 0px;">, c3<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px;">(<span style="margin: 0px; padding: 0px; color: #993333;">SELECT v1<span style="margin: 0px; padding: 0px; color: #66cc66;">, v2<span style="margin: 0px; padding: 0px;">, v3 <span style="margin: 0px; padding: 0px; color: #993333;">FROM table2<span style="margin: 0px; padding: 0px; color: #66cc66;">)</span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">答案是可以的，具体的语法如下：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 3 4 5 6 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE table1 alias <span style="margin: 0px; padding: 0px;">SET <span style="margin: 0px; padding: 0px; color: #66cc66;">(column_name<span style="margin: 0px; padding: 0px;">,column_name <span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px;">= <span style="margin: 0px; padding: 0px;">( <span style="margin: 0px; padding: 0px; color: #993333;">SELECT <span style="margin: 0px; padding: 0px; color: #66cc66;">(column_name<span style="margin: 0px; padding: 0px;">, column_name<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px; color: #993333;">FROM table2 <span style="margin: 0px; padding: 0px;">WHERE column_name <span style="margin: 0px; padding: 0px; color: #66cc66;">= alias<span style="margin: 0px; padding: 0px;">.column_name<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px; color: #993333;">WHERE column_name <span style="margin: 0px; padding: 0px; color: #66cc66;">= <span style="margin: 0px; padding: 0px; color: #993333;">VALUE</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">下面是这样一个例子： 两个表a、b，想使b中的memo字段值等于a表中对应id的name值 表a：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 3 4 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">id    name  <span style="margin: 0px; padding: 0px; color: #cc66cc;">1     王  <span style="margin: 0px; padding: 0px;">2     李  <span style="margin: 0px; padding: 0px;">3     张</span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">表b：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 3 4 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">id    ClientName    <span style="margin: 0px; padding: 0px; color: #cc66cc;">1  <span style="margin: 0px; padding: 0px;">2  <span style="margin: 0px; padding: 0px;">3</span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><strong>(MS SQL Server)语句：</strong></p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE b   <span style="margin: 0px; padding: 0px;">SET   ClientName    <span style="margin: 0px; padding: 0px; color: #66cc66;">= a<span style="margin: 0px; padding: 0px;">.name    <span style="margin: 0px; padding: 0px; color: #993333;">FROM a<span style="margin: 0px; padding: 0px; color: #66cc66;">,b    <span style="margin: 0px; padding: 0px; color: #993333;">WHERE a<span style="margin: 0px; padding: 0px; color: #66cc66;">.id <span style="margin: 0px; padding: 0px;">= b<span style="margin: 0px; padding: 0px;">.id</span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">(Oralce)语句：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE b   <span style="margin: 0px; padding: 0px;">SET   <span style="margin: 0px; padding: 0px; color: #66cc66;">(ClientName<span style="margin: 0px; padding: 0px;">)    <span style="margin: 0px; padding: 0px;">=   <span style="margin: 0px; padding: 0px;">(<span style="margin: 0px; padding: 0px; color: #993333;">SELECT name <span style="margin: 0px; padding: 0px;">FROM a <span style="margin: 0px; padding: 0px;">WHERE b<span style="margin: 0px; padding: 0px; color: #66cc66;">.id <span style="margin: 0px; padding: 0px;">= a<span style="margin: 0px; padding: 0px;">.id<span style="margin: 0px; padding: 0px;">)</span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">update set from 语句格式 当where和set都需要关联一个表进行查询时，整个update执行时，就需要对被关联的表进行两次扫描，显然效率比较低。</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">对于这种情况，Sybase和SQL SERVER的解决办法是使用UPDATE&#8230;SET&#8230;FROM&#8230;WHERE&#8230;的语法，实际上就是从源表获取更新数据。</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">在 SQL 中，表连接（left join、right join、inner join 等）常常用于 select 语句。 其实在 SQL 语法中，这些连接也是可以用于 update 和 delete 语句的，在这些语句中使用 join 还常常得到事半功倍的效果。</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE T_OrderForm <span style="margin: 0px; padding: 0px;">SET T_OrderForm<span style="margin: 0px; padding: 0px; color: #66cc66;">.SellerID <span style="margin: 0px; padding: 0px;">=B<span style="margin: 0px; padding: 0px;">.L_TUserID <span style="margin: 0px; padding: 0px; color: #993333;">FROM T_OrderForm A <span style="margin: 0px; padding: 0px;">LEFT <span style="margin: 0px; padding: 0px;">JOIN T_ProductInfo   B <span style="margin: 0px; padding: 0px;">ON B<span style="margin: 0px; padding: 0px; color: #66cc66;">.L_ID<span style="margin: 0px; padding: 0px;">=A<span style="margin: 0px; padding: 0px;">.ProductID</span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">用来同步两个表的数据!</p><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">Oralce和DB2都支持的语法：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE A <span style="margin: 0px; padding: 0px;">SET <span style="margin: 0px; padding: 0px; color: #66cc66;">(A1<span style="margin: 0px; padding: 0px;">, A2<span style="margin: 0px; padding: 0px;">, A3<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px;">= <span style="margin: 0px; padding: 0px;">(<span style="margin: 0px; padding: 0px; color: #993333;">SELECT B1<span style="margin: 0px; padding: 0px; color: #66cc66;">, B2<span style="margin: 0px; padding: 0px;">, B3 <span style="margin: 0px; padding: 0px; color: #993333;">FROM B <span style="margin: 0px; padding: 0px;">WHERE A<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px;">= B<span style="margin: 0px; padding: 0px;">.ID<span style="margin: 0px; padding: 0px;">)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">MS SQL Server不支持这样的语法，相对应的写法为：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE A  <span style="margin: 0px; padding: 0px;">SET A1 <span style="margin: 0px; padding: 0px; color: #66cc66;">= B1<span style="margin: 0px; padding: 0px;">, A2 <span style="margin: 0px; padding: 0px;">= B2<span style="margin: 0px; padding: 0px;">, A3 <span style="margin: 0px; padding: 0px;">= B3  <span style="margin: 0px; padding: 0px; color: #993333;">FROM A <span style="margin: 0px; padding: 0px;">LEFT <span style="margin: 0px; padding: 0px;">JOIN B <span style="margin: 0px; padding: 0px;">ON A<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px;">= B<span style="margin: 0px; padding: 0px;">.ID</span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">个人感觉MS SQL Server的Update语法功能更为强大。MS SQL SERVER的写法：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE A <span style="margin: 0px; padding: 0px;">SET A1 <span style="margin: 0px; padding: 0px; color: #66cc66;">= B1<span style="margin: 0px; padding: 0px;">, A2 <span style="margin: 0px; padding: 0px;">= B2<span style="margin: 0px; padding: 0px;">, A3 <span style="margin: 0px; padding: 0px;">= B3 <span style="margin: 0px; padding: 0px; color: #993333;">FROM A<span style="margin: 0px; padding: 0px; color: #66cc66;">, B <span style="margin: 0px; padding: 0px; color: #993333;">WHERE A<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px;">= B<span style="margin: 0px; padding: 0px;">.ID</span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><p style="margin: 10px auto; padding-top: 0px; padding-bottom: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;">在Oracle和DB2中的写法就比较麻烦了，如下：</p><div style="margin: 0px; padding: 0px; color: #333333; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 14px;"><table style="margin: 0px; padding: 0px; border-collapse: collapse; border-spacing: 0px; max-width: 850px; border-style: solid; border-color: #dfdfdf; word-break: break-word;"><tbody style="margin: 0px; padding: 0px;"><tr style="margin: 0px; padding: 0px;"><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;">1 2 </pre></td><td style="margin: 0px; padding: 8px 14px; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; min-width: 50px;"><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word;"><span style="margin: 0px; padding: 0px; color: #993333; font-weight: bold;">UPDATE A <span style="margin: 0px; padding: 0px;">SET <span style="margin: 0px; padding: 0px; color: #66cc66;">(A1<span style="margin: 0px; padding: 0px;">, A2<span style="margin: 0px; padding: 0px;">, A3<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px;">= <span style="margin: 0px; padding: 0px;">(<span style="margin: 0px; padding: 0px; color: #993333;">SELECT B1<span style="margin: 0px; padding: 0px; color: #66cc66;">, B2<span style="margin: 0px; padding: 0px;">, B3 <span style="margin: 0px; padding: 0px; color: #993333;">FROM B <span style="margin: 0px; padding: 0px;">WHERE A<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px;">= B<span style="margin: 0px; padding: 0px;">.ID<span style="margin: 0px; padding: 0px;">) <span style="margin: 0px; padding: 0px; color: #993333;">WHERE ID <span style="margin: 0px; padding: 0px;">IN <span style="margin: 0px; padding: 0px; color: #66cc66;">(<span style="margin: 0px; padding: 0px; color: #993333;">SELECT B<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px; color: #993333;">FROM B <span style="margin: 0px; padding: 0px;">WHERE A<span style="margin: 0px; padding: 0px; color: #66cc66;">.ID <span style="margin: 0px; padding: 0px;">= B<span style="margin: 0px; padding: 0px;">.ID<span style="margin: 0px; padding: 0px;">)</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></pre></td></tr></tbody></table></div><img src ="http://www.cnitblog.com/yide/aggbug/92186.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-05-19 14:42 <a href="http://www.cnitblog.com/yide/archive/2020/05/19/92186.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>交叉连接CROSS JOIN</title><link>http://www.cnitblog.com/yide/archive/2020/04/28/92148.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Tue, 28 Apr 2020 09:08:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/04/28/92148.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92148.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/04/28/92148.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92148.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92148.html</trackback:ping><description><![CDATA[<pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; white-space: pre-wrap; overflow-wrap: break-word; font-size: 12px; font-family: &quot;Courier New&quot; !important;"><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">如果不带WHERE条件子句，它将会返回被连接的两个表的笛卡尔积，返回结果的行数等于两个表行数的乘积；  举例,下列A、B、C 执行结果相同，但是效率不一样：  A:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span> table1 <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">CROSS</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">JOIN</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> table2  B:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">SELECT</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">FROM</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> table1,table2   C:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">select</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">from</span> table1 a <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">inner</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">join</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> table2 b  A:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">select</span> a.<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span>,b.<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">from</span> table1 a,table2 b <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">where</span> a.id<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">b.id  B:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">select</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">from</span> table1 a <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">cross</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">join</span> table2 b <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">where</span> a.id<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span>b.id (注：<span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">cross</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;"> join后加条件只能用where,不能用on)  C:</span><span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">select</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">*</span> <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">from</span> table1 a <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">inner</span> <span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">join</span> table2 b <span style="margin: 0px; padding: 0px; color: #0000ff; line-height: 1.5 !important;">on</span> a.id<span style="margin: 0px; padding: 0px; color: #808080; line-height: 1.5 !important;">=</span><span style="margin: 0px; padding: 0px; line-height: 1.5 !important;">b.id  一般不建议使用方法A和B，因为如果有WHERE子句的话，往往会先生成两个表行数乘积的行的数据表然后才根据WHERE条件从中选择。   因此，如果两个需要求交际的表太大，将会非常非常慢，不建议使用。</span></pre><img src ="http://www.cnitblog.com/yide/aggbug/92148.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-04-28 17:08 <a href="http://www.cnitblog.com/yide/archive/2020/04/28/92148.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>PIVOT行转列</title><link>http://www.cnitblog.com/yide/archive/2020/04/24/92143.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Fri, 24 Apr 2020 09:07:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/04/24/92143.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92143.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/04/24/92143.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92143.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92143.html</trackback:ping><description><![CDATA[<div><span style="font-size: 11px;">在数据库操作中，有些时候我们遇到需要实现&#8220;行转列&#8221;的需求，例如一下的表为某店铺的一周收入情况表：</span></div><div><span style="font-size: 11px;"><br /></span></div><div><span style="font-size: 11px;">WEEK_INCOME(WEEK VARCHAR(10),INCOME DECIMAL)</span></div><div><span style="font-size: 11px;">我们先插入一些模拟数据：</span></div><div><span style="font-size: 11px;"><br /></span></div><div><span style="font-size: 11px;">INSERT INTO WEEK_INCOME&nbsp;</span></div><div><span style="font-size: 11px;">SELECT '星期一',1000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期二',2000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期三',3000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期四',4000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期五',5000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期六',6000</span></div><div><span style="font-size: 11px;">UNION ALL</span></div><div><span style="font-size: 11px;">SELECT '星期日',7000</span></div><div><span style="font-size: 11px;">********************************************</span></div><div><span style="font-size: 11px;"><div></div><div></div><div>&nbsp;SELECT WEEK,INCOME FROM WEEK_INCOME</div><div></div><div></div><div></div><div>&nbsp;SELECT&nbsp;&nbsp;</div><div>SUM(CASE WEEK WHEN '星期一' THEN INCOME END) AS [星期一],</div><div>SUM(CASE WEEK WHEN '星期二' THEN INCOME END) AS [星期二],</div><div>SUM(CASE WEEK WHEN '星期三' THEN INCOME END) AS [星期三],</div><div>SUM(CASE WEEK WHEN '星期四' THEN INCOME END) AS [星期四],</div><div>SUM(CASE WEEK WHEN '星期五' THEN INCOME END) AS [星期五],</div><div>SUM(CASE WEEK WHEN '星期六' THEN INCOME END) AS [星期六],</div><div>SUM(CASE WEEK WHEN '星期日' THEN INCOME END) AS [星期日]</div><div>FROM WEEK_INCOME</div><div>&nbsp;</div><div></div><div></div><div></div><div>&nbsp;</div><div>SELECT [星期一],[星期二],[星期三],[星期四],[星期五],[星期六],[星期日]</div><div>FROM WEEK_INCOME</div><div>PIVOT</div><div>(</div><div>&nbsp; &nbsp; SUM(INCOME) for [week] in([星期一],[星期二],[星期三],[星期四],[星期五],[星期六],[星期日])</div><div>)TBL33</div><div>&nbsp;</div></span></div><div><span style="font-size: 11px;"><br /></span></div><div><span style="font-size: 11px;"><br /></span></div><img src ="http://www.cnitblog.com/yide/aggbug/92143.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-04-24 17:07 <a href="http://www.cnitblog.com/yide/archive/2020/04/24/92143.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>存储过程中的临时表为什么以#开头？#是不是有特殊的含义</title><link>http://www.cnitblog.com/yide/archive/2020/04/18/92139.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Sat, 18 Apr 2020 06:31:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2020/04/18/92139.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/92139.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2020/04/18/92139.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/92139.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/92139.html</trackback:ping><description><![CDATA[<span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;">你要理解为什么要用临时表，其实临时表又称为过渡表。</span><br style="content: &quot;&quot;; display: block; width: 705px; height: 0px; margin: 20px 0px; color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;" /><br style="content: &quot;&quot;; display: block; width: 705px; height: 0px; margin: 20px 0px; color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;" /><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;">临时表有两种类型：本地和全局。它们在名称</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; display: inline-block; width: 0.1px; height: 0.1px; opacity: 0; font-size: 0px; overflow: hidden;">zhidao</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;">、可见性以及可用性上有区别。本地临时表的名称以单个数字符</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; display: inline-block; width: 0.1px; height: 0.1px; opacity: 0; font-size: 0px; overflow: hidden;">回</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;">号 (#) 打头；它们仅对当前的用户连接是可见的；当用户从 SQL Server 实例断开连接时被删除。全局临时表的</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; display: inline-block; width: 0.1px; height: 0.1px; opacity: 0; font-size: 0px; overflow: hidden;">答</span><span style="color: #333333; font-family: &quot;PingFang SC&quot;, &quot;Lantinghei SC&quot;, &quot;Microsoft YaHei&quot;, arial, 宋体, sans-serif, tahoma; font-size: 16px;">名称以两个数字符号 (##) 打头，创建后对任何用户都是可见的，当所有引用该表的用户从 SQL Server 断开连接时被删除。<br /><br />存储过程sql语句拼接：<br /><br />注意引号数量<br /></span><div><span style="font-size: 11px;">&nbsp;SELECT @sql = @sql + ' and&nbsp; 发生日期 &gt;='+''''+ @bgdate+ ''''+' and&nbsp; 发生日期 &lt;='+''''+ @eddate +''''</span></div><div><span style="font-size: 11px;">&nbsp;&nbsp;</span><span style="font-size: 11px;">SELECT @sql = @sql + '&nbsp; and 名称 like&nbsp; '+'''%abc%'''+' '<br /><br /><br /></span><div>&nbsp;SELECT @sql = @sql + '&nbsp; &nbsp; &nbsp;and&nbsp; id= '+@id+&nbsp; &nbsp;''</div></div><img src ="http://www.cnitblog.com/yide/aggbug/92139.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/yide/" target="_blank">青蛙學堂</a> 2020-04-18 14:31 <a href="http://www.cnitblog.com/yide/archive/2020/04/18/92139.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>SQLserver数据库导入Mysql数据库</title><link>http://www.cnitblog.com/yide/archive/2012/05/14/79862.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Mon, 14 May 2012 02:54:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/05/14/79862.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/79862.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/05/14/79862.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/79862.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/79862.html</trackback:ping><description><![CDATA[<h1 style="text-align: left; line-height: 2em; widows: 2; text-transform: none; background-color: rgb(255,255,255); font-variant: normal; font-style: normal; text-indent: 0px; padding-left: 0.2em; font-family: Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); font-size: 1.2em; word-break: break-all; word-spacing: 0px; background-origin: initial; background-clip: initial; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" class="xspace-title">SQLserver数据库导入Mysql数据库的体验</h1>
<div style="text-align: left; overflow-x: auto; overflow-y: hidden; widows: 2; text-transform: none; background-color: rgb(255,255,255); text-indent: 0px; margin: 0.5em auto; width: 554px; font: 12px/1.8em Arial, Helvetica, sans-serif; white-space: normal; orphans: 2; letter-spacing: normal; color: rgb(0,0,0); word-break: break-all; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px" id="xspace-showmessage" class="xspace-itemmessage">因工作需要，要将存放在<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'sql');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">sql</strong></u></a><span class="Apple-converted-space">&nbsp;</span><a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'server');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">server</strong></u></a><a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, '%CA%FD%BE%DD%BF%E2');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">数据库</strong></u></a>中的数据全部导入到<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'mysql');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">mysql</strong></u></a>数据库中，在网上搜集相关资料，找到两种方法，现在分别谈谈对他们的看法。<br style="line-height: normal; word-break: break-all" />第一种是安装mysql ODBC，利用sql server的导出功能，选择mysql数据源，进行数据的直接导出，这种方法很简便，但是针对实际应用有很多弊端，最主要体现就是数据类型问题，首先，sql server数据库中<br style="line-height: normal; word-break: break-all" />的ntext,image等数据类型的数据无法直接写入到mysql数据库中，据说只要稍加改动就可以，可惜偶这只菜鸟还没想到如何改动，其次，因为偶在mysql中的数据库<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, '%C9%E8%BC%C6');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">设计</strong></u></a>中将时间都设成int型(保存的是时间戳)，所以在数据导过来后，就会出现冲突，再次，这种方法生成的mysql数据表的字段类型都不很合适，所以此种方法我觉得不能提倡。<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />第二种是利用<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'php');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">php</strong></u></a>或<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'asp');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">asp</strong></u></a>脚本来实现数据的导入功能，这种方法需要编写程序，但灵活性大，操作也不是那么困难，一切都尽在你的掌握之中，现简单介绍一下该方法<br style="line-height: normal; word-break: break-all" />前提条件是你的mysql环境已经搭建好了，先建好目标数据库，再将所有的表结构用sql语句生成，现在万事具备，只缺数据了。<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />可以通过下面的php脚本来实现sql server中mydb数据库的user表中数据向mysql中mydb数据库导入<br style="line-height: normal; word-break: break-all" />&lt;?<br style="line-height: normal; word-break: break-all" />$cnx = odbc_connect('web', 'admin', '123456');//'web'是<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, 'sqlserver');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">sqlserver</strong></u></a>中mydb的数据源名，'admin'是访问mydb的用户名，'123456'是访问mydb的密码<br style="line-height: normal; word-break: break-all" />$cur= odbc_exec( $cnx, 'select * from user' );//打开sql server中mydb数据库的user表<br style="line-height: normal; word-break: break-all" />$num_row=0;<br style="line-height: normal; word-break: break-all" />$conn=mysql_pconnect("localhost","root","123456");// 连接mysql<br style="line-height: normal; word-break: break-all" />@mysql_select_db('mydb',$conn) or<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />die("无法连接到数据库，请与<a style="line-height: normal; color: rgb(0,153,153); word-break: break-all; text-decoration: underline" onclick="javascript:tagshow(event, '%B9%DC%C0%ED');" href="javascript:;" target="_self"><u style="line-height: normal; word-break: break-all"><strong style="line-height: normal; word-break: break-all">管理</strong></u></a>员联系！");//打开mysql的mydb数据库<br style="line-height: normal; word-break: break-all" />while( odbc_fetch_row( $cur )) //从sql server的mydb库中的user表逐条取出数据，如果对数据进行选择，可在前面的select语句中加上条件判断<br style="line-height: normal; word-break: break-all" />{<br style="line-height: normal; word-break: break-all" />$num_row++;<br style="line-height: normal; word-break: break-all" />$field1 = odbc_result( $cur, 1 ); // 这里的参数i(1,2,3..)指的是记录集中的第i个域，你可以有所选择地进行选取，fieldi得到对应域的值，然后你可以对fieldi进行操作<br style="line-height: normal; word-break: break-all" />$field2 = odbc_result( $cur, 2 );<br style="line-height: normal; word-break: break-all" />$field3 = odbc_result( $cur, 3 );<br style="line-height: normal; word-break: break-all" />$field4 = odbc_result( $cur, 4 );<br style="line-height: normal; word-break: break-all" />$field5 = odbc_result( $cur, 5 );<br style="line-height: normal; word-break: break-all" />$field6 = odbc_result( $cur, 6 );<br style="line-height: normal; word-break: break-all" />$field5 = timetoint($field5); //这里是对sql server中的datetime类型的字段进行相应转换处理，转换成我所需要的int型<br style="line-height: normal; word-break: break-all" />$querystring = "insert into user<br style="line-height: normal; word-break: break-all" />(id,name,username,password,recdate)<br style="line-height: normal; word-break: break-all" />values('$field1','$field2','$field3','$field4','$field5')" ;<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />mysql_query($querystring,$conn);<br style="line-height: normal; word-break: break-all" />}<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />function timetoint($str){<br style="line-height: normal; word-break: break-all" />$arr1=split(" ",$str);<br style="line-height: normal; word-break: break-all" />$datestr=$arr1[0];<br style="line-height: normal; word-break: break-all" />$timestr=$arr1[1];<br style="line-height: normal; word-break: break-all" />$arr_date=split("-",$datestr);<br style="line-height: normal; word-break: break-all" />$arr_time=split(":",$timestr);<br style="line-height: normal; word-break: break-all" />$year=$arr_date[0];<br style="line-height: normal; word-break: break-all" />$month=$arr_date[1];<br style="line-height: normal; word-break: break-all" />$day=$arr_date[2];<br style="line-height: normal; word-break: break-all" />$hour=$arr_time[0];<br style="line-height: normal; word-break: break-all" />$minute=$arr_time[1];<br style="line-height: normal; word-break: break-all" />$second=$arr_time[2];<br style="line-height: normal; word-break: break-all" />$time_int=mktime($hour,$minute,$second,$month,$day,$year);<br style="line-height: normal; word-break: break-all" />return $time_int;<br style="line-height: normal; word-break: break-all" />}<br style="line-height: normal; word-break: break-all" />?&gt;<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />将该段脚本存成sql.php，在服务器上执行，就可以将服务器上sql server中mydb数据库的user表中的数据导入到mysql中mydb数据库的user表中去。其他表的操作与此雷同，就不赘述了。<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />下面再介绍一下asp脚本实现sql server中mydb数据库的数据向mysql中mydb数据库导入<br style="line-height: normal; word-break: break-all" />&lt;%<br style="line-height: normal; word-break: break-all" />set conn=server.createobject("adodb.connection")<br style="line-height: normal; word-break: break-all" />conn.open 'web', 'admin', '123456' // 'web'是sqlserver中mydb的数据源名，'admin'是访问mydb的用户名，'123456'是访问mydb的密码<br style="line-height: normal; word-break: break-all" />set rs=server.createobject("adodb.recordset")<br style="line-height: normal; word-break: break-all" />sql="select ID,name,username,password,datediff(s,'1970-01-01 00:00:00',recdate)-8*3600,reid,filename,fileContentType,filevalue from senddate" //这条sql语句实现了将datetime类型的recdate字段转化成unix时间戳的int型<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />rs.open sql,conn,1,3<br style="line-height: normal; word-break: break-all" />set conn1=server.createobject("adodb.connection")<br style="line-height: normal; word-break: break-all" />conn1.open "myoa","root","q1-d6=7?"<br style="line-height: normal; word-break: break-all" />i=1<br style="line-height: normal; word-break: break-all" />do while not rs.eof<br style="line-height: normal; word-break: break-all" />field1 = rs(0)<br style="line-height: normal; word-break: break-all" />field2 = rs(1)<br style="line-height: normal; word-break: break-all" />field3 = rs(2)<br style="line-height: normal; word-break: break-all" />field4 = rs(3)<br style="line-height: normal; word-break: break-all" />field5 = rs(4)<br style="line-height: normal; word-break: break-all" />sql1 = "insert into user(ID,name,username,password,recdate)<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />values("&amp;field1&amp;",'"&amp;field2&amp;"','"&amp;field3&amp;"','"&amp;field4&amp;"',"&amp;field5&amp;")"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />conn1.execute sql1<br style="line-height: normal; word-break: break-all" />rs.movenext<br style="line-height: normal; word-break: break-all" />i=i+1<br style="line-height: normal; word-break: break-all" />loop<br style="line-height: normal; word-break: break-all" />rs.close<br style="line-height: normal; word-break: break-all" />set rs=nothing<br style="line-height: normal; word-break: break-all" />conn.close<br style="line-height: normal; word-break: break-all" />set conn=nothing<br style="line-height: normal; word-break: break-all" />conn1.close<br style="line-height: normal; word-break: break-all" />set conn1=nothing<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />%&gt;<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />以上两个是分别采用php脚本和asp脚本对user表的数据进行由sql server到mysql的导入其间我采用2种回避的方法来避免ntext,image类型数据的传递，一种是将ntext字段改为nvarchar(4000)，因为实际情况，原始数据中该字段的数据长度都未超过4000个字，所以并没有出现数据截断，另一个手段是将image类型数据取出来写到文件中，以文件形式保存，将文件路径存到数据库中，方法见下：<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />function makeattach(fileContentType,filevalue,i)<br style="line-height: normal; word-break: break-all" />select case fileContentType<br style="line-height: normal; word-break: break-all" />case "application/msword"<br style="line-height: normal; word-break: break-all" />ext="doc"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "application/vnd.ms-excel"<br style="line-height: normal; word-break: break-all" />ext="exl"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "application/vnd.ms-powerpoint"<br style="line-height: normal; word-break: break-all" />ext="pps"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "application/x-rar-compressed"<br style="line-height: normal; word-break: break-all" />ext="rar"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "application/x-zip-compressed"<br style="line-height: normal; word-break: break-all" />ext="zip"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "image/gif"<br style="line-height: normal; word-break: break-all" />ext="gif"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "image/pjpeg"<br style="line-height: normal; word-break: break-all" />ext="jpg"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case "text/plain"<br style="line-height: normal; word-break: break-all" />ext="txt"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />case else<br style="line-height: normal; word-break: break-all" />ext="x"<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />end select<br style="line-height: normal; word-break: break-all" />if ext&lt;&gt;"x" then<br style="line-height: normal; word-break: break-all" />set fso=server.createobject("FileSystemObject")<br style="line-height: normal; word-break: break-all" />fName="attech"&amp;i&amp;"."&amp;ext<br style="line-height: normal; word-break: break-all" />Dir="d:attach"<br style="line-height: normal; word-break: break-all" />If fso.FileExists(Dir &amp; fName) Then fso.deletefile Dir &amp; fName<br style="line-height: normal; word-break: break-all" />If fName&lt;&gt;"" AND NOT fso.FileExists(Dir &amp; fName) Then<br style="line-height: normal; word-break: break-all" />Set strm1=Server.CreateObject("ADODB.Stream")<br style="line-height: normal; word-break: break-all" />strm1.Open<br style="line-height: normal; word-break: break-all" />strm1.Type=1 'Binary<br style="line-height: normal; word-break: break-all" />strm1.Write filevalue<br style="line-height: normal; word-break: break-all" />strm1.SaveToFile Dir &amp; fName,2<br style="line-height: normal; word-break: break-all" />Set strm1=Nothing<br style="line-height: normal; word-break: break-all" />end if<br style="line-height: normal; word-break: break-all" />makeattach=fName<br style="line-height: normal; word-break: break-all" />end if<br style="line-height: normal; word-break: break-all" />end function<br style="line-height: normal; word-break: break-all" /><br style="line-height: normal; word-break: break-all" />这个函数有3个输入参数，第一个是文件的contentType，第二个是文件的二进制数值，第三个是个可以区别文件名的变量，先根据contentType确定所存文件的后缀名，然后就是将二进制数值保存成指定文件名的文件，并将文件名作为输出参数返回，将返回的参数作为数据写到mysql的数据库中保存。<br style="line-height: normal; word-break: break-all" />时间匆忙，先总结到这里，希望这些文字能对有需要的人有些帮助，少走些弯路，感谢您的阅读。：）<br style="line-height: normal; word-break: break-all" /></div><img src ="http://www.cnitblog.com/yide/aggbug/79862.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-05-14 10:54 <a href="http://www.cnitblog.com/yide/archive/2012/05/14/79862.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>dtswizard--sqlserver2005数据导入导出工具</title><link>http://www.cnitblog.com/yide/archive/2012/05/14/79861.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Mon, 14 May 2012 02:48:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/05/14/79861.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/79861.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/05/14/79861.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/79861.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/79861.html</trackback:ping><description><![CDATA[<font color="#000000" size="3" face="Times New Roman">dtswizard--sqlserver2005数据导入导出工具</font><img src ="http://www.cnitblog.com/yide/aggbug/79861.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-05-14 10:48 <a href="http://www.cnitblog.com/yide/archive/2012/05/14/79861.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL中返回刚插入记录的自增ID </title><link>http://www.cnitblog.com/yide/archive/2012/04/25/79282.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Wed, 25 Apr 2012 12:16:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/04/25/79282.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/79282.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/04/25/79282.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/79282.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/79282.html</trackback:ping><description><![CDATA[<p><font color="#000000" size="3" face="Times New Roman">SQL中返回刚插入记录的自增ID @@IDENTITY<br /></font></p>
<p><font color="#000000" size="3" face="Times New Roman"><br />一、要获取此ID,最简单的方法就是:(以下举一简单实用的例子) </font></p>
<p><font color="#000000" size="3" face="Times New Roman">-创建数据库和表</font></p>
<p><font color="#000000" size="3" face="Times New Roman">1.create database MyDataBase <br />2.use MyDataBase <br />3.create table mytable ( id int identity(1,1), name varchar(20) ) <br />create database MyDataBase<br />use MyDataBase<br />create table mytable ( id int identity(1,1), name varchar(20) )<br />&nbsp;</font></p>
<p><font color="#000000" size="3" face="Times New Roman">--执行这个SQL,就能查出来刚插入记录对应的自增列的值</font></p>
<p><font color="#000000" size="3" face="Times New Roman">1.insert into mytable values('李四') <br />2.select @@identity <br />insert into mytable values('李四')<br />select @@identity<br />二、三种方式的比较</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SQL Server 2000中，有三个比较类似的功能：他们分别是：SCOPE_IDENTITY、IDENT_CURRENT 和 @@IDENTITY，它们都返回插入到 IDENTITY 列中的值。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">IDENT_CURRENT 返回为任何会话和任何作用域中的特定表最后生成的标识值。IDENT_CURRENT 不受作用域和会话的限制，而受限于指定的表。IDENT_CURRENT 返回为任何会话和作用域中的特定表所生成的值。 @@IDENTITY 返回为当前会话的所有作用域中的任何表最后生成的标识值。 SCOPE_IDENTITY 返回为当前会话和当前作用域中的任何表最后生成的标识值</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SCOPE_IDENTITY 和 @@IDENTITY 返回在当前会话中的任何表内所生成的最后一个标识值。但是，SCOPE_IDENTITY 只返回插入到当前作用域中的值；@@IDENTITY 不受限于特定的作用域。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">例如，有两个表 T1 和 T2，在 T1 上定义了一个 INSERT 触发器。当将某行插入 T1 时，触发器被激发，并在 T2 中插入一行。此例说明了两个作用域：一个是在 T1 上的插入，另一个是作为触发器的结果在 T2 上的插入。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">假设 T1 和 T2 都有 IDENTITY 列，@@IDENTITY 和 SCOPE_IDENTITY 将在 T1 上的 INSERT 语句的最后返回不同的值。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">@@IDENTITY 返回插入到当前会话中任何作用域内的最后一个 IDENTITY 列值，该值是插入 T2 中的值。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SCOPE_IDENTITY() 返回插入 T1 中的 IDENTITY 值，该值是发生在相同作用域中的最后一个 INSERT。如果在作用域中发生插入语句到标识列之前唤醒调用 SCOPE_IDENTITY() 函数，则该函数将返回 NULL 值。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">而IDENT_CURRENT('T1') 和 IDENT_CURRENT('T2') 返回的值分别是这两个表最后自增的值。</font></p>
<p><font color="#000000" size="3" face="Times New Roman">ajqc的实验:(40条本地线程,40+40条远程线程同时并发测试,插入1200W行),得出的结论是: 1.在典型的级联应用中.不能用@@IDENTITY,在CII850,256M SD的机器上1W多行时就会并发冲突.在P42.8C,512M DDR上,才6000多行时就并发冲突. 2.SCOPE_IDENTITY()是绝对可靠的,可以用在存储过程中,连触发器也不用建,没并发冲突</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SELECT IDENT_CURRENT('TableName') --返回指定表中生成的最后一个标示值</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SELECT IDENT_INCR('TableName')--返回指定表的标示字段增量值</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SELECT IDENT_SEED('TableName')--返回指定表的标示字段种子值</font></p>
<p><font color="#000000" size="3" face="Times New Roman">返回最后插入记录的自动编号 SELECT IDENT_CURRENT('TableName') 返回下一个自动编号:</font></p>
<p><font color="#000000" size="3" face="Times New Roman">SELECT IDENT_CURRENT('TableName') + (SELECT IDENT_INCR('TableName'))<br />SELECT @@IDENTITY --返回当前会话所有表中生成的最后一个标示值</font></p><img src ="http://www.cnitblog.com/yide/aggbug/79282.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-25 20:16 <a href="http://www.cnitblog.com/yide/archive/2012/04/25/79282.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>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>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>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><item><title>c#--arrayList实例</title><link>http://www.cnitblog.com/yide/archive/2012/03/08/77981.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Thu, 08 Mar 2012 00:49:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/08/77981.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77981.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/08/77981.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77981.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77981.html</trackback:ping><description><![CDATA[<p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">例一</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//Dictionary<br />System.Collections.DictionaryEntry dic=new System.Collections.DictionaryEntry("key1","value1");</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//ArrayList<br />System.Collections.ArrayList list=new System.Collections.ArrayList();<br />list.Add(1);<br />list.Add(2);<br />for(int i=0;i&lt;list.Count;i++)<br />{<br />&nbsp;System.Console.WriteLine(list[i]);<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//HashTable<br />System.Collections.Hashtable table=new System.Collections.Hashtable();<br />table.Add("table1",1);<br />table.Add("table2",2);<br />System.Collections.IDictionaryEnumerator d=table.GetEnumerator();<br />while(d.MoveNext())<br />{<br />&nbsp;System.Console.WriteLine(d.Entry.Key);<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//Queue<br />System.Collections.Queue queue=new System.Collections.Queue();<br />queue.Enqueue(1);<br />queue.Enqueue(2);</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">System.Console.WriteLine(queue.Peek());<br />while(queue.Count&gt;0)<br />{<br />&nbsp;System.Console.WriteLine(queue.Dequeue());<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//SortedList<br />System.Collections.SortedList list=new System.Collections.SortedList();<br />list.Add("key2",2);<br />list.Add("key1",1);<br />for(int i=0;i&lt;list.Count;i++)<br />{<br />&nbsp;System.Console.WriteLine(list.GetKey(i));<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">//Stack<br />System.Collections.Stack stack=new System.Collections.Stack();<br />stack.Push(1);<br />stack.Push(2);</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">System.Console.WriteLine(stack.Peek());<br />while(stack.Count&gt;0)<br />{<br />&nbsp;System.Console.WriteLine(stack.Pop());<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; "><br />例二</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">using System;<br />using System.Collections;</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">namespace myCon<br />{<br />&nbsp;class Student<br />&nbsp;{<br />&nbsp; public Student(){}<br />&nbsp; public Student(string strName)<br />&nbsp;</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp; private string name;<br />&nbsp; public string Name<br />&nbsp; {<br />&nbsp;&nbsp; get{ return name; }<br />&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp; public string ToString()<br />&nbsp; {<br />&nbsp;&nbsp; return name;<br />&nbsp; }<br />&nbsp;}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;class Connect: IEnumerable<br />&nbsp;{<br />&nbsp; IEnum ie = new IEnum();<br />&nbsp; public void Add(object obj)<br />&nbsp; {<br />&nbsp;&nbsp; ie.lst.Add(obj);<br />&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp; public void ReMove(object obj)<br />&nbsp; {<br />&nbsp;&nbsp; ie.lst.Remove(obj);<br />&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp; public IEnumerator GetEnumerator()<br />&nbsp; {<br />&nbsp;&nbsp; return ie;<br />&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp; class IEnum: IEnumerator<br />&nbsp; {<br />&nbsp;&nbsp; public int idx = -1;<br />&nbsp;&nbsp; public ArrayList lst = new ArrayList();</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp; public void Reset()<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; idx = -1;<br />&nbsp;&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp; public object Current<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; get<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp; if (idx&gt;=0 &amp;&amp; idx&lt;lst.Count)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return lst[idx];<br />&nbsp;&nbsp;&nbsp;&nbsp; return null;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;&nbsp; public bool MoveNext()<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; idx++;<br />&nbsp;&nbsp;&nbsp; return idx&lt;lst.Count;<br />&nbsp;&nbsp; }<br />&nbsp; }</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;}<br />&nbsp;<br />&nbsp;<br />&nbsp;class Class1<br />&nbsp;{<br />&nbsp; static void Main(string[] args)<br />&nbsp; {<br />&nbsp;&nbsp; Connect con = new Connect();<br />&nbsp;&nbsp; con.Add(new Student("aaa"));<br />&nbsp;&nbsp; con.Add(new Student("bbb"));<br />&nbsp;&nbsp; con.Add(new Student("ccc"));<br />&nbsp;&nbsp; foreach(Student stu in con)<br />&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp; Console.WriteLine(stu.Name);<br />&nbsp;&nbsp; }<br />&nbsp;&nbsp;<br />&nbsp; }<br />&nbsp;}<br />}</p><p style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; text-align: left; ">&nbsp;</p><img src ="http://www.cnitblog.com/yide/aggbug/77981.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 08:49 <a href="http://www.cnitblog.com/yide/archive/2012/03/08/77981.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>C#--conn--mysql</title><link>http://www.cnitblog.com/yide/archive/2012/03/07/77965.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Wed, 07 Mar 2012 08:46:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/07/77965.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77965.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/07/77965.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77965.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77965.html</trackback:ping><description><![CDATA[<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 20px; padding-bottom: 0px; padding-left: 20px; width: 658px; word-wrap: break-word; font-size: 14px; line-height: 26px; overflow-x: hidden; overflow-y: hidden; position: relative; font-family: Arial, Helvetica, sans-serif, SimSun; border-image: initial; "><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; ">第一种方案DBC.NET解决方案 MyODBC Driver<br /><br />优点: <a href="http://wenwen.soso.com/z/Search.e?sp=S%E5%85%BC%E5%AE%B9%E6%80%A7&amp;ch=w.search.yjjlink&amp;cid=w.search.yjjlink" target="_blank" style="color: #005599; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #005599; ">兼容性</a>好, 易于使用<br />缺点: 运行效率差, 原因是架构包含太多层<br /><br />架构:<br />ODBC.NET应用程序 &amp;lt;-&amp;gt;ODBC.NET Provider &amp;lt;-&amp;gt; MYSQL ODBC 启动 &amp;lt;-&amp;gt; MYSQL API<br />&amp;lt;-&amp;gt; MYSQL <a href="http://wenwen.soso.com/z/Search.e?sp=S%E6%9C%8D%E5%8A%A1%E5%99%A8&amp;ch=w.search.yjjlink&amp;cid=w.search.yjjlink" target="_blank" style="color: #005599; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #005599; ">服务器</a><br /><br />安装步骤:<br />1, 下载安装最新的.NET FRAMEWORK<br />2,安装MYSQL 服务端<br />3, 下载安装2.6版以上的MDAC(Microsoft Data Access Components )<br />地址:http://www.microsoft.com/data/<br />4, 下载 ODBC.NET Provider<br />http://www.microsoft.com/downloads/...ReleaseID=35715<br />5, 安装MySQL ODBC Driver ---- MyODBC 3.51;<br />http://www.mysql.com/downloads/api-myodbc-3.51.html<br />6, 安装一个MyODBC DSN<br /><br />ODBC.NET安装后有如下几个操作类OdbcCommand, OdbcConnection<br /><br /><br /><br />第二种方案:使用MYSQL NATIVE .NET Providers(推荐这个, 因为安装和使用都非常方便)<br /><br />优点:速度快, 开发容易<br />缺点:是非标准访问技术<br /><br />1,你可以参看dbProvider<br /><br />http://www.einfodesigns.com/products.aspx<br /><br />2, 或者MySQLNet<br />http://sourceforge.net/projects/mysqlnet/<br /><br />3,推荐这个corelab开放的一个MYSQL.NET<a href="http://wenwen.soso.com/z/Search.e?sp=S%E6%8E%A7%E4%BB%B6&amp;ch=w.search.yjjlink&amp;cid=w.search.yjjlink" target="_blank" style="color: #005599; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #005599; ">控件</a><br />http://crlab.com/mysqlnet/<br />有免费的下载<br /><br />有如下几个类似于SQL 操作类<br />MySqlConnection, MySqlCommand,<br />MySqlDataReader,MySqlDataAdapter,MySqlParameter,MySqlTransaction<br /><br />================================================<br /><br />下面贴出第二种解决方案的部分<a href="http://wenwen.soso.com/z/Search.e?sp=S%E6%BA%90%E4%BB%A3%E7%A0%81&amp;ch=w.search.yjjlink&amp;cid=w.search.yjjlink" target="_blank" style="color: #005599; border-bottom-width: 1px; border-bottom-style: dotted; border-bottom-color: #005599; ">源代码</a>, 基本和SQL COMMAND等使用没有区别<br /><br />string DataSource = "localhost";<br />string Database = "GameLib";<br />string UserID = "root";<br />string Password = "root-2003-";<br /><br />string MyConString = Data Source=" + DataSource +<br />";Database=" + Database +<br />";User ID=" + UserID +<br />";Password=" + Password;<br /><br />try{<br /><br />MySqlConnection mycon = new MySqlConnection(MyConString);<br />mycon.Open();<br />}<br /><br />finally{<br />mycon.Close();<br />}<br /><br /><br /><br />第三种方案: 使用OLEDB.NET<br /><br />MYSQL暂时不支持 MyOLEDB, 所以不采用OLEDB这个方案<br /></pre></div><div style="margin-top: 0px; margin-right: 20px; margin-bottom: 0px; margin-left: 20px; padding-top: 42px; padding-right: 0px; padding-bottom: 5px; padding-left: 0px; position: relative; overflow-x: hidden; overflow-y: hidden; zoom: 1; font-family: Arial, Helvetica, sans-serif, SimSun; border-image: initial; "><div id="solveDIV511351376" style="margin-top: 0px; margin-right: 7px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; height: 24px; float: left; border-top-width: 2px; border-right-width: 2px; border-bottom-width: 2px; border-left-width: 2px; border-top-color: #ffffff; border-right-color: #ffffff; border-bottom-color: #ffffff; border-left-color: #ffffff; border-image: initial; "><ul style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; list-style-type: none; list-style-position: initial; list-style-image: initial; background-image: url(http://cache.soso.com/wenwen/i/evaluation_bg_20110804.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; float: left; height: 22px; overflow-x: hidden; overflow-y: hidden; zoom: 1; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #b6b6b6; border-right-color: #b6b6b6; border-bottom-color: #b6b6b6; border-left-color: #b6b6b6; border-image: initial; background-position: 0px -70px; background-repeat: repeat no-repeat; "><li style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: -3px; padding-top: 0px; padding-right: 2px; padding-bottom: 0px; padding-left: 2px; background-image: url(http://cache.soso.com/wenwen/i/evaluation_bg_20110804.png); background-attachment: initial; background-origin: initial; background-clip: initial; background-color: initial; float: left; min-width: 62px; white-space: nowrap; text-align: center; background-position: 0px -46px; background-repeat: no-repeat no-repeat; "><br /></li></ul></div></div><img src ="http://www.cnitblog.com/yide/aggbug/77965.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-07 16:46 <a href="http://www.cnitblog.com/yide/archive/2012/03/07/77965.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Conn--mySql</title><link>http://www.cnitblog.com/yide/archive/2012/03/07/77964.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Wed, 07 Mar 2012 08:16:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/07/77964.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77964.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/07/77964.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77964.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77964.html</trackback:ping><description><![CDATA[<div style="clear: both; line-height: 20px; padding-bottom: 10px; color: #494949; font-family: Verdana, 宋体, sans-serif; text-align: left; background-color: #c1cfd0; "><h2><br /></h2></div><div id="sina_keyword_ad_area2"  "="" style="width: 690px; clear: both; padding-top: 18px; font-size: 14px; line-height: 21px; padding-bottom: 30px; word-wrap: normal; word-break: normal; overflow-x: hidden; overflow-y: hidden; font-family: simsun; color: #494949; text-align: left; background-color: #c1cfd0; "><p style="margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; 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; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; ">using System;<br />using System.Configuration;<br />using MySql.Data.MySqlClient;<br />/// &lt;summary&gt;<br />/// TestDatebase 的摘要说明<br />/// &lt;/summary&gt;<br />public class TestDatebase<br />{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public TestDatebase()<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;// TODO: 在此处添加构造函数逻辑<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void Main(String[] args)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;MySqlConnection mysql = getMySqlCon();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//查询sql<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String sqlSearch = "select * from student";<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//插入sql<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String sqlInsert = "insert into student values (12,'张三',25,'大专')";<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//修改sql<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String sqlUpdate = "update student set name='李四' where id= 3";<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//删除sql<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String sqlDel = "delete from student where id = 12";<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//打印SQL语句<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine(sqlDel);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//四种语句对象<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//MySqlCommand mySqlCommand = getSqlCommand(sqlSearch, mysql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//MySqlCommand mySqlCommand = getSqlCommand(sqlInsert, mysql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//MySqlCommand mySqlCommand = getSqlCommand(sqlUpdate, mysql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;MySqlCommand mySqlCommand = getSqlCommand(sqlDel, mysql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;mysql.Open();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//getResultset(mySqlCommand);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//getInsert(mySqlCommand);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//getUpdate(mySqlCommand);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;getDel(mySqlCommand);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//记得关闭<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;mysql.Close();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String readLine = Console.ReadLine();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 建立mysql数据库链接<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;returns&gt;&lt;/returns&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static MySqlConnection getMySqlCon()<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String mysqlStr = "Database=test;Data Source=127.0.0.1;User Id=root;Password=root;pooling=false;CharSet=utf8;port=3306";<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;// String mySqlCon = ConfigurationManager.ConnectionStrings["MySqlCon"].ConnectionString;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;MySqlConnection mysql = new MySqlConnection(mysqlStr);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;return mysql;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 建立执行命令语句对象<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="sql"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="mysql"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;returns&gt;&lt;/returns&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static MySqlCommand getSqlCommand(String sql,MySqlConnection mysql)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;MySqlCommand mySqlCommand = new MySqlCommand(sql, mysql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;//&nbsp;<wbr>&nbsp;MySqlCommand mySqlCommand = new MySqlCommand(sql);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;// mySqlCommand.Connection = mysql;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;return mySqlCommand;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 查询并获得结果集并遍历<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="mySqlCommand"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void getResultset(MySqlCommand mySqlCommand)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;MySqlDataReader reader = mySqlCommand.ExecuteReader();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;try<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;while (reader.Read())<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;if (reader.HasRows)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine("编号:" + reader.GetInt32(0) + "|姓名:" + reader.GetString(1) + "|年龄:" + reader.GetInt32(2) + "|学历:" + reader.GetString(3));<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;catch (Exception)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{</p><p style="margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; 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; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine("查询失败了！");<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;finally<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;reader.Close();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 添加数据<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="mySqlCommand"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void getInsert(MySqlCommand mySqlCommand)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;try<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;mySqlCommand.ExecuteNonQuery();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;catch (Exception ex)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String message = ex.Message;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine("插入数据失败了！" + message);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 修改数据<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="mySqlCommand"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void getUpdate(MySqlCommand mySqlCommand)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;try<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;mySqlCommand.ExecuteNonQuery();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;catch (Exception ex)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{</p><p style="margin-bottom: 5px; padding-top: 0px; padding-bottom: 0px; 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; list-style-type: none; list-style-position: initial; list-style-image: initial; word-wrap: normal; word-break: normal; ">&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String message = ex.Message;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine("修改数据失败了！" + message);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// 删除数据<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;/summary&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;/// &lt;param name="mySqlCommand"&gt;&lt;/param&gt;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;public static void getDel(MySqlCommand mySqlCommand)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;try<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;mySqlCommand.ExecuteNonQuery();<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;catch (Exception ex)<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;{<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;String message = ex.Message;<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;Console.WriteLine("删除数据失败了！" + message);<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;}<br />}<br /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "><br /><br /><br /><br /><br />朋友下了个程序让我把数据库改为mysql，以前是连接sql server的。查了下资料，花了不少时间终于搞定了。把过程记录如下:</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">首先在c#里面是没有原生态支持mysql的，谷歌了下，找到了MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0这个类库，下载下来安装下得到如下几个dll:<img src="http://pic002.cnblogs.com/images/2010/131741/2010121616003090.jpg" alt="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; 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; float: left; " /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">接着在vs里面添加引用</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "><img src="http://pic002.cnblogs.com/images/2010/131741/2010121616012845.jpg" alt="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; 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; " /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">下面就是开始写连接字符串了查了下这个dll的文档</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">得到MySqlConnection写为:MySqlConnection conn=new MySqlConnection(string cs);其中cs表示连接字符串可以用new MySqlConnectionString("服务器地址","数据库","登录名","密码").AsString;得到，接下来的操作基本就和SqlConnection一致了.</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">按照上面的配置我开始从数据库检索数据了，写了个测试的方法，结果居然连不上报错了！于是想到是没有为mysql配置远程登录权限,依旧谷歌查到一篇文章参见:</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "><a href="http://dev.firnow.com/course/7_databases/mysql/Mysqljs/2008324/107030.html" target="_blank" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; color: black; ">http://dev.firnow.com/course/7_databases/mysql/Mysqljs/2008324/107030.html</a></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">在数据库mysql里面的user表执行如下sql语句:</p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "></p><div style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 0px; padding-top: 5px; padding-right: 5px; padding-bottom: 5px; padding-left: 5px; background-color: #f5f5f5; font-family: 'Courier New'; border-top-color: #cccccc; border-right-color: #cccccc; border-bottom-color: #cccccc; border-left-color: #cccccc; border-image: initial; word-break: break-all; overflow-x: auto; overflow-y: auto; "><pre style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; white-space: pre-wrap; word-wrap: break-word; font-family: 'Courier New'; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; "><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #008080; ">1</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">grant</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #808080; ">all</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">privileges</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">on</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #808080; ">*</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">.</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #808080; ">*</span> <span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">to</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "> "创建的用户名 @"</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #808080; ">%</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; ">" identified </span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; color: #0000ff; ">by</span><span style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: 1.5; "> "密码";</span></div></pre></div><span style="font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">结果搞定了，贴个连接上的图(数据库中的表被朋友删掉故查询不到)</span><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "><img src="http://pic002.cnblogs.com/images/2010/131741/2010121616215621.jpg" alt="" style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; 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; " /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; "><br /></p><p style="margin-top: 5px; margin-right: auto; margin-bottom: 5px; margin-left: auto; padding-top: 0px; padding-bottom: 0px; font-family: verdana, 'ms song', 宋体, Arial, 微软雅黑, Helvetica, sans-serif; line-height: 22px; ">&nbsp;</p><br /><br /><br /><br /><br /><br /><br /><p>&nbsp;</p></div><img src ="http://www.cnitblog.com/yide/aggbug/77964.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-07 16:16 <a href="http://www.cnitblog.com/yide/archive/2012/03/07/77964.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql使用方法</title><link>http://www.cnitblog.com/yide/archive/2012/03/07/77962.html</link><dc:creator>青蛙學堂</dc:creator><author>青蛙學堂</author><pubDate>Wed, 07 Mar 2012 07:01:00 GMT</pubDate><guid>http://www.cnitblog.com/yide/archive/2012/03/07/77962.html</guid><wfw:comment>http://www.cnitblog.com/yide/comments/77962.html</wfw:comment><comments>http://www.cnitblog.com/yide/archive/2012/03/07/77962.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/yide/comments/commentRss/77962.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/yide/services/trackbacks/77962.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 有很多朋友虽然安装好了mysql但却不知如何使用它。在这篇文章中我们就从连接mysql、修改密码、增加用户等方面来学习一些mysql的常用命令。一、连接mysql。格式： mysql -h主机地址 -u用户名 －p用户密码1、 例1：连接到本机上的mysql。首先在打开DOS窗口，然后进入目录mysql in，再键入命令mysql -uroot -p， 回车后提示你输密码，如果刚安装好mysql，...&nbsp;&nbsp;<a href='http://www.cnitblog.com/yide/archive/2012/03/07/77962.html'>阅读全文</a><img src ="http://www.cnitblog.com/yide/aggbug/77962.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-07 15:01 <a href="http://www.cnitblog.com/yide/archive/2012/03/07/77962.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>