首页 数据库 mysql教程 如何在.NET中使用MySQL数据库

如何在.NET中使用MySQL数据库

Jun 07, 2016 pm 04:07 PM
.net mysql 使用 数据库

在.NET中一直使用Sql Server做数据库。前几天学习通过JDBC使用Java连接MySql数据库,我就想.NET是否同样可以使用MySql数据库呢?答案是肯定的,方法也很简单,在这里我使用C#作为编程语言,将自己整理出来的方法同大家一起分享。 欲在.NET中使用MySql数据库

在.NET中一直使用Sql Server做数据库。前几天学习通过JDBC使用Java连接MySql数据库,我就想.NET是否同样可以使用MySql数据库呢?答案是肯定的,方法也很简单,在这里我使用C#作为编程语言,将自己整理出来的方法同大家一起分享。

欲在.NET中使用MySql数据库,其步骤是:
1. 下载MySql驱动包
2. 引用驱动包中已经编译好的MySql类组件
3. 编写代码

步骤一:下载MySql驱动包

在我写篇文章的时候,最新的驱动包是5.2,支持Visual Studio 2008。官方下载地址是http://dev.mysql.com/downloads/connector/net/5.2.html

步骤二:引入组件

下载的文件是一个压缩文件,将其解压缩到本地磁盘。找到bin文件夹中的MySql.Data.dll文件,这个就是我们要引用的组件。通过Visual Studio将其引用到你的项目中

步骤三:编码,我编写了一个控制台的示例,并将重要的部分都添加了注释,代码如下:

<font color="#008080">1<img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922471.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_0_59_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_0_59_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_0_59_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_0_59_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922472.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_0_59_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_0_59_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_0_59_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_0_59_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ></font><span id="Codehighlighter1_0_59_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_0_59_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000">*<br></span><span style="COLOR: #008080"> 2</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"> * 程序名称:使用.NET连接MySql数据库<br></span><span style="COLOR: #008080"> 3</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"> * 作者:吴磊<br></span><span style="COLOR: #008080"> 4</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"> * 日期:2009年01月17日<br></span><span style="COLOR: #008080"> 5</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922476.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"> </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 6</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"><br></span><span style="COLOR: #008080"> 7</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #008000">//</span><span style="COLOR: #008000"> 使用MySql.Data.MySqlClient命名空间</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080"> 8</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> System;<br></span><span style="COLOR: #008080"> 9</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #0000ff">using</span><span style="COLOR: #000000"> MySql.Data.MySqlClient;<br></span><span style="COLOR: #008080">10</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"><br></span><span style="COLOR: #008080">11</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922477.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #0000ff">namespace</span><span style="COLOR: #000000"> Project_Personnel.db<br></span><span style="COLOR: #008080">12</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922471.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_169_2590_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_169_2590_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_169_2590_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_169_2590_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922472.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_169_2590_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_169_2590_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_169_2590_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_169_2590_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ></span><span id="Codehighlighter1_169_2590_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_169_2590_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">13</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">    </span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> dbManage<br></span><span style="COLOR: #008080">14</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_194_2588_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_194_2588_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_194_2588_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_194_2588_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_194_2588_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_194_2588_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_194_2588_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_194_2588_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >    </span><span id="Codehighlighter1_194_2588_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_194_2588_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">15</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_204_311_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_204_311_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_204_311_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_204_311_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_204_311_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_204_311_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_204_311_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_204_311_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >        </span><span id="Codehighlighter1_204_311_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_204_311_Open_Text"><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> </span><span style="COLOR: #808080"><summary></summary></span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">16</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> 连接到MySql数据库并返回连接对象<br></span><span style="COLOR: #008080">17</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> </span><span style="COLOR: #808080"></span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">18</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        </span><span style="COLOR: #808080">///</span><span style="COLOR: #008000"> </span><span style="COLOR: #808080"><returns></returns></span><span style="COLOR: #008000">数据库连接对象</span><span style="COLOR: #808080"></span></span><br><span style="COLOR: #008080">19</span><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">private</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> MySqlConnection getCon()<br></span><span style="COLOR: #008080">20</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_367_1026_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_367_1026_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_367_1026_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_367_1026_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_367_1026_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_367_1026_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_367_1026_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_367_1026_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >        </span><span id="Codehighlighter1_367_1026_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_367_1026_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">21</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            MySqlConnection myCon </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">null</span><span style="COLOR: #000000">;<br></span><span style="COLOR: #008080">22</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">23</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_439_843_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_439_843_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_439_843_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_439_843_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_439_843_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_439_843_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_439_843_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_439_843_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_439_843_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_439_843_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">24</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_457_687_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_457_687_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_457_687_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_457_687_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_457_687_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_457_687_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_457_687_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_457_687_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                </span><span id="Codehighlighter1_457_687_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_457_687_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">25</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 * Server:数据库服务器。localhost表示本机<br></span><span style="COLOR: #008080">26</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 * Database:数据库名称。school表示mySql中一个名为school的数据库<br></span><span style="COLOR: #008080">27</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 * Uid:用户名<br></span><span style="COLOR: #008080">28</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 * Pwd:密码<br></span><span style="COLOR: #008080">29</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 * CharSet:使用的字符编码。不设置可能产生乱码<br></span><span style="COLOR: #008080">30</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                 </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">31</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                myCon </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> MySqlConnection(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Server=localhost;Database=school;<br>Uid=root;Pwd=123;CharSet=utf8;</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">32</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                myCon.Open();<br></span><span style="COLOR: #008080">33</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">34</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (MySqlException e)<br></span><span style="COLOR: #008080">35</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_893_990_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_893_990_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_893_990_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_893_990_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_893_990_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_893_990_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_893_990_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_893_990_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_893_990_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_893_990_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">36</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">抛出连接MySql数据库的异常</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">37</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                </span><span style="COLOR: #0000ff">throw</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> Exception(e.Message);<br></span><span style="COLOR: #008080">38</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">39</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> myCon;<br></span><span style="COLOR: #008080">40</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">41</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"><br></span><span style="COLOR: #008080">42</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        </span><span style="COLOR: #0000ff">public</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">static</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">void</span><span style="COLOR: #000000"> Main()<br></span><span style="COLOR: #008080">43</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1070_2582_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1070_2582_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1070_2582_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1070_2582_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1070_2582_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1070_2582_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1070_2582_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1070_2582_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >        </span><span id="Codehighlighter1_1070_2582_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_1070_2582_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">44</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #0000ff">try</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">45</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1100_2227_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1100_2227_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1100_2227_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1100_2227_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1100_2227_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1100_2227_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1100_2227_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1100_2227_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_1100_2227_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_1100_2227_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">46</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">从shool表中检索数据的sql语句(别误会,我是在school数据库中建立了一个school表)</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">47</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                MySqlCommand myCmd </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">new</span><span style="COLOR: #000000"> MySqlCommand(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">select * from school</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, getCon());<br></span><span style="COLOR: #008080">48</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">               <br></span><span style="COLOR: #008080">49</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">执行检索语句并将执行结果赋值给MySqlDataReader对象</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">50</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                MySqlDataReader myReader </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> myCmd.ExecuteReader();<br></span><span style="COLOR: #008080">51</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"><br></span><span style="COLOR: #008080">52</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">进行读取</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">53</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                </span><span style="COLOR: #0000ff">while</span><span style="COLOR: #000000"> (myReader.Read())<br></span><span style="COLOR: #008080">54</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1472_2213_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1472_2213_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1472_2213_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1472_2213_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1472_2213_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1472_2213_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1472_2213_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1472_2213_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                </span><span id="Codehighlighter1_1472_2213_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_1472_2213_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">55</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">myReader的FieldCount属性表示列数</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">56</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                    </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> (</span><span style="COLOR: #0000ff">int</span><span style="COLOR: #000000"> i </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">0</span><span style="COLOR: #000000">; i </span><span style="COLOR: #000000"><span style="COLOR: #000000"> myReader.FieldCount; i</span><span style="COLOR: #000000">++</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">57</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1608_2129_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1608_2129_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1608_2129_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1608_2129_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1608_2129_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1608_2129_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1608_2129_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1608_2129_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                    </span><span id="Codehighlighter1_1608_2129_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_1608_2129_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">58</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1634_1784_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1634_1784_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1634_1784_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1634_1784_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1634_1784_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1634_1784_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1634_1784_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1634_1784_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                        </span><span id="Codehighlighter1_1634_1784_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/**/</span><span id="Codehighlighter1_1634_1784_Open_Text"><span style="COLOR: #008000">/*</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">59</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                         * 提示:如果使用此if语句,会产生异常:数据为空,不能对空值调用此方法或属性。<br></span><span style="COLOR: #008080">60</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                         * 判断索引为i的列中的值是否为空,如果为空输出NULL<br></span><span style="COLOR: #008080">61</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                         </span><span style="COLOR: #008000">*/</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">62</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                        </span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> (</span><span style="COLOR: #000000">!</span><span style="COLOR: #000000">myReader[i].Equals(DBNull.Value))<br></span><span style="COLOR: #008080">63</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1872_1965_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1872_1965_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_1872_1965_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_1872_1965_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_1872_1965_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_1872_1965_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_1872_1965_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_1872_1965_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                        </span><span id="Codehighlighter1_1872_1965_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_1872_1965_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">64</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                            Console.Write(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">{0,10}</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, myReader[i]);<br></span><span style="COLOR: #008080">65</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                        }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">66</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                        </span><span style="COLOR: #0000ff">else</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">67</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2019_2107_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2019_2107_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_2019_2107_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_2019_2107_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2019_2107_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2019_2107_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_2019_2107_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_2019_2107_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >                        </span><span id="Codehighlighter1_2019_2107_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_2019_2107_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">68</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                            Console.Write(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">{0,10}</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">Null</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">);<br></span><span style="COLOR: #008080">69</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                        }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">70</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                    }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">71</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                    </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">换行</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">72</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">                    Console.WriteLine();<br></span><span style="COLOR: #008080">73</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">74</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">75</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">捕获MySql异常</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">76</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (MySqlException e)<br></span><span style="COLOR: #008080">77</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2301_2362_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2301_2362_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_2301_2362_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_2301_2362_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2301_2362_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2301_2362_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_2301_2362_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_2301_2362_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_2301_2362_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_2301_2362_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">78</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                Console.WriteLine(e.Message);<br></span><span style="COLOR: #008080">79</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">80</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #008000">//</span><span style="COLOR: #008000">捕获其他异常</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080">81</span><span style="COLOR: #008000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top"></span><span style="COLOR: #000000">            </span><span style="COLOR: #0000ff">catch</span><span style="COLOR: #000000"> (Exception e)<br></span><span style="COLOR: #008080">82</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2428_2489_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2428_2489_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_2428_2489_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_2428_2489_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2428_2489_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2428_2489_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_2428_2489_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_2428_2489_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_2428_2489_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_2428_2489_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">83</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                Console.WriteLine(e.Message);<br></span><span style="COLOR: #008080">84</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">85</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            </span><span style="COLOR: #0000ff">finally</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">86</span><span style="COLOR: #000000"><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224717.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2522_2572_Open_Image" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2522_2572_Open_Text').style.display='none'; document.getElementById('Codehighlighter1_2522_2572_Closed_Image').style.display='inline'; document.getElementById('Codehighlighter1_2522_2572_Closed_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" ><img  class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224718.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" id="Codehighlighter1_2522_2572_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; document.getElementById('Codehighlighter1_2522_2572_Closed_Text').style.display='none'; document.getElementById('Codehighlighter1_2522_2572_Open_Image').style.display='inline'; document.getElementById('Codehighlighter1_2522_2572_Open_Text').style.display='inline';" align="top" alt="如何在.NET中使用MySQL数据库" >            </span><span id="Codehighlighter1_2522_2572_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224715.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt=""></span><span id="Codehighlighter1_2522_2572_Open_Text"><span style="COLOR: #000000">{<br></span><span style="COLOR: #008080">87</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922473.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">                Console.ReadKey();<br></span><span style="COLOR: #008080">88</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">            }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">89</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">        }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">90</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/09224724.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">    }</span></span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080">91</span><span style="COLOR: #000000"><img class="fit-image lazy" src="/static/imghw/default1.png" data-src="/files/uploadimg/20090119/0922476.gif" onload="javascript:if(this.width>498)this.   style="max-width:90%" onmousewheel="javascript:return big(this)" alt="" align="top">}</span></span><span style="COLOR: #000000"><br></span></span>
登录后复制

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

热门话题

Java教程
1664
14
CakePHP 教程
1421
52
Laravel 教程
1315
25
PHP教程
1266
29
C# 教程
1239
24
MySQL和PhpMyAdmin:核心功能和功能 MySQL和PhpMyAdmin:核心功能和功能 Apr 22, 2025 am 12:12 AM

MySQL和phpMyAdmin是强大的数据库管理工具。1)MySQL用于创建数据库和表、执行DML和SQL查询。2)phpMyAdmin提供直观界面进行数据库管理、表结构管理、数据操作和用户权限管理。

甲骨文在商业世界中的作用 甲骨文在商业世界中的作用 Apr 23, 2025 am 12:01 AM

Oracle不仅是数据库公司,还是云计算和ERP系统的领导者。1.Oracle提供从数据库到云服务和ERP系统的全面解决方案。2.OracleCloud挑战AWS和Azure,提供IaaS、PaaS和SaaS服务。3.Oracle的ERP系统如E-BusinessSuite和FusionApplications帮助企业优化运营。

在MySQL中解释外键的目的。 在MySQL中解释外键的目的。 Apr 25, 2025 am 12:17 AM

在MySQL中,外键的作用是建立表与表之间的关系,确保数据的一致性和完整性。外键通过引用完整性检查和级联操作维护数据的有效性,使用时需注意性能优化和避免常见错误。

C#作为多功能.NET语言:应用程序和示例 C#作为多功能.NET语言:应用程序和示例 Apr 26, 2025 am 12:26 AM

C#在企业级应用、游戏开发、移动应用和Web开发中均有广泛应用。1)在企业级应用中,C#常用于ASP.NETCore开发WebAPI。2)在游戏开发中,C#与Unity引擎结合,实现角色控制等功能。3)C#支持多态性和异步编程,提高代码灵活性和应用性能。

比较和对比Mysql和Mariadb。 比较和对比Mysql和Mariadb。 Apr 26, 2025 am 12:08 AM

MySQL和MariaDB的主要区别在于性能、功能和许可证:1.MySQL由Oracle开发,MariaDB是其分支。2.MariaDB在高负载环境中性能可能更好。3.MariaDB提供了更多的存储引擎和功能。4.MySQL采用双重许可证,MariaDB完全开源。选择时应考虑现有基础设施、性能需求、功能需求和许可证成本。

SQL与MySQL:澄清两者之间的关系 SQL与MySQL:澄清两者之间的关系 Apr 24, 2025 am 12:02 AM

SQL是一种用于管理关系数据库的标准语言,而MySQL是一个使用SQL的数据库管理系统。SQL定义了与数据库交互的方式,包括CRUD操作,而MySQL实现了SQL标准并提供了额外的功能,如存储过程和触发器。

将C#.NET应用程序部署到Azure/AWS:逐步指南 将C#.NET应用程序部署到Azure/AWS:逐步指南 Apr 23, 2025 am 12:06 AM

如何将C#.NET应用部署到Azure或AWS?答案是使用AzureAppService和AWSElasticBeanstalk。1.在Azure上,使用AzureAppService和AzurePipelines自动化部署。2.在AWS上,使用AmazonElasticBeanstalk和AWSLambda实现部署和无服务器计算。

REDIS:了解其架构和目的 REDIS:了解其架构和目的 Apr 26, 2025 am 12:11 AM

Redis是一种内存数据结构存储系统,主要用作数据库、缓存和消息代理。它的核心特点包括单线程模型、I/O多路复用、持久化机制、复制与集群功能。 Redis在实际应用中常用于缓存、会话存储和消息队列,通过选择合适的数据结构、使用管道和事务、以及进行监控和调优,可以显着提升其性能。

See all articles