Rumah > Artikel > pangkalan data > 访问MySQL数据库用.NET!
以下的文章主要介绍的是用.NET访问MySQL数据库的实际操作步骤,我们大家都知道.NET的数据库本身就支持mssql(WINDOWS平台上强大的数据库平台)Server,但是并不是其他数据库不支持,而是微软基于自身利益需要。 在支持、营销上推自己的MySQL数据库产品;但是作
以下的文章主要介绍的是用.NET访问MySQL数据库的实际操作步骤,我们大家都知道 .NET的数据库本身就支持mssql(WINDOWS平台上强大的数据库平台)Server,但是并不是其他数据库不支持,而是微软基于自身利益需要。
在支持、营销上推自己的MySQL数据库产品;但是作为平台战略,他并非排斥其他数据库,而是参考java体系提出了一套数据库访问规范,让各个第三方进行开发,提供特定的驱动。
MySQL(和PHP搭配之最佳组合)是免费的数据库,在成本上具有无可替代的优势,但是目前来讲,并没有提供。微软把MySQL(和PHP搭配之最佳组合)当作ODBC数据库,可以按照ODBC.Net规范进行访问,具体参考
而实际上,针对ODBC。Net的需要配置DSN的麻烦,而是出现了一个开源的系统MySQL(和PHP搭配之最佳组合)DriverCS,对MySQL(和PHP搭配之最佳组合)的开发进行了封装,实现了.net环境下对于MySQL数据库系统的访问。
通过阅读源代码,我们看到MySQL(和PHP搭配之最佳组合)DriverCS的思路是利用C函数的底层库来操纵数据库的,通常提供对MySQL(和PHP搭配之最佳组合)数据库的访问的MySQL数据库的C DLL是名为libMySQL(和PHP搭配之最佳组合).dll的驱动文件,MySQL(和PHP搭配之最佳组合)DriverCS作为一个.net库进行封装C风格的驱动。
具体如何进行呢?
打开工程后,我们看到其中有一个比较特殊的.cs文件CPrototypes.cs:
以下是引用片段:
<ol class="dp-xml"> <li class="alt"><span><span>#region LICENSE </span></span></li> <li><span>/* </span></li> <li class="alt"><span>MySQL(和PHP搭配之最佳组合)DriverCS: An C# driver for MySQL(和PHP搭配之最佳组合). </span></li> <li><span>Copyright (c) 2002 Manuel Lucas Vi馻s Livschitz. </span></li> <li class="alt"><span>This file is part of MySQL(和PHP搭配之最佳组合)DriverCS. </span></li> <li><span>MySQL(和PHP搭配之最佳组合)DriverCS is free software; you can redistribute it and/or modify </span></li> <li class="alt"><span>it under the terms of the GNU General Public License as published by </span></li> <li><span>the Free Software Foundation; either version 2 of the License, or </span></li> <li class="alt"><span>(at your option) any later version. </span></li> <li><span>MySQL(和PHP搭配之最佳组合)DriverCS is distributed in the hope that it will be useful, </span></li> <li class="alt"><span>but WITHOUT ANY WARRANTY; without even the implied warranty of </span></li> <li><span>MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the </span></li> <li class="alt"><span>GNU General Public License for more details. </span></li> <li><span>You should have received a copy of the GNU General Public License </span></li> <li class="alt"><span>along with MySQL(和PHP搭配之最佳组合)DriverCS; if not, write to the Free Software </span></li> <li><span>Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA </span></li> <li class="alt"><span>*/ </span></li> <li><span>#endregion </span></li> <li class="alt"><span>using System; </span></li> <li><span>using System.Data; </span></li> <li class="alt"><span>using System.Runtime.InteropServices; </span></li> <li><span>namespace MySQL(和PHP搭配之最佳组合)DriverCS </span></li> <li class="alt"><span>{ </span></li> <li><span>//[StructLayout(LayoutKind.Sequential)] </span></li> <li class="alt"><span>public class MySQL(和PHP搭配之最佳组合)_FIELD_FACTORY </span></li> <li><span>{ </span></li> <li class="alt"><span>static string version; </span></li> <li><span>public static IMySQL(和PHP搭配之最佳组合)_FIELD GetInstance() </span></li> <li class="alt"><span>{ </span></li> <li> <span>if (</span><span class="attribute">version</span><span>==null) </span> </li> <li class="alt"><span>{ </span></li> <li> <span class="attribute">version</span><span> = </span><span class="attribute-value">CPrototypes</span><span>.GetClientInfo(); </span> </li> <li class="alt"><span>} </span></li> <li> <span>if (version.CompareTo("4.1.2-alpha")</span><span class="tag">></span><span>=0) </span> </li> <li class="alt"><span>{ </span></li> <li><span>return new MySQL(和PHP搭配之最佳组合)_FIELD_VERSION_5(); </span></li> <li class="alt"><span>} </span></li> <li><span>else </span></li> <li class="alt"><span>return new MySQL(和PHP搭配之最佳组合)_FIELD_VERSION_3(); </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li><span>public interface IMySQL(和PHP搭配之最佳组合)_FIELD </span></li> <li class="alt"><span>{ </span></li> <li><span>string Name{get;} </span></li> <li class="alt"><span>uint Type{get;} </span></li> <li><span>long Max_Length {get;} </span></li> <li class="alt"><span>} </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Field descriptor </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>[StructLayout(LayoutKind.Sequential)]//"3.23.32", 4.0.1-alpha </span></li> <li><span>internal class MySQL(和PHP搭配之最佳组合)_FIELD_VERSION_3: IMySQL(和PHP搭配之最佳组合)_FIELD </span></li> <li class="alt"><span>{ </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Name of column </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string name; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Table of column if column was a field </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string table; </span></li> <li><span>//public string org_table; /* Org table name if table was an alias */ </span></li> <li class="alt"><span>//public string db; /* Database for table */ </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// def </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string def; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// max_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long max_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Div flags </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint flags; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Number of decimals in field </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint decimals; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Type of field. Se MySQL(和PHP搭配之最佳组合)_com.h for types </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint type; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Name </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string Name </span></li> <li><span>{ </span></li> <li class="alt"><span>get{return name;} </span></li> <li><span>} </span></li> <li class="alt"> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li><span>/// Type </span></li> <li class="alt"> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li><span>public uint Type </span></li> <li class="alt"><span>{ </span></li> <li><span>get{return type;} </span></li> <li class="alt"><span>} </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Max_Length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long Max_Length </span></li> <li><span>{ </span></li> <li class="alt"><span>get {return max_length;} </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Field descriptor </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>[StructLayout(LayoutKind.Sequential)] </span></li> <li><span>internal class MySQL(和PHP搭配之最佳组合)_FIELD_VERSION_5: IMySQL(和PHP搭配之最佳组合)_FIELD </span></li> <li class="alt"><span>{ </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Name of column </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string name; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Original column name, if an alias </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string org_name; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Table of column if column was a field </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string table; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Org table name if table was an alias </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string org_table; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Database for table </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string db; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Catalog for table </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>//public string catalog; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// def </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string def; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// max_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long max_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// name_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>//public uint name_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// org_name_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint org_name_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// table_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint table_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// org_table_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint org_table_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// db_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint db_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// catalog_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint catalog_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// def_length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint def_length; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Div flags </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint flags; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Number of decimals in field </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint decimals; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Character set </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint charsetnr; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Type of field. Se MySQL(和PHP搭配之最佳组合)_com.h for types </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public uint type; </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Name </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public string Name </span></li> <li><span>{ </span></li> <li class="alt"><span>get {return name;} </span></li> <li><span>} </span></li> <li class="alt"> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li><span>/// Type </span></li> <li class="alt"> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li><span>public uint Type </span></li> <li class="alt"><span>{ </span></li> <li><span>get {return type;} </span></li> <li class="alt"><span>} </span></li> <li> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li class="alt"><span>/// Max_Length </span></li> <li> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li class="alt"><span>public long Max_Length </span></li> <li><span>{ </span></li> <li class="alt"><span>get {return max_length;} </span></li> <li><span>} </span></li> <li class="alt"><span>} </span></li> <li><span>//[StructLayout(LayoutKind.Explicit)] </span></li> <li class="alt"><span>public enum enum_field_types </span></li> <li><span>{ </span></li> <li class="alt"><span>FIELD_TYPE_DECIMAL, FIELD_TYPE_TINY, </span></li> <li><span>FIELD_TYPE_SHORT, FIELD_TYPE_LONG, </span></li> <li class="alt"><span>FIELD_TYPE_FLOAT, FIELD_TYPE_DOUBLE, </span></li> <li><span>FIELD_TYPE_NULL, FIELD_TYPE_TIMESTAMP, </span></li> <li class="alt"><span>FIELD_TYPE_LONGLONG,FIELD_TYPE_INT24, </span></li> <li><span>FIELD_TYPE_DATE, FIELD_TYPE_TIME, </span></li> <li class="alt"><span>FIELD_TYPE_DATETIME, FIELD_TYPE_YEAR, </span></li> <li><span>FIELD_TYPE_NEWDATE, </span></li> <li class="alt"> <span class="attribute">FIELD_TYPE_ENUM</span><span>=</span><span class="attribute-value">247</span><span>, </span> </li> <li> <span class="attribute">FIELD_TYPE_SET</span><span>=</span><span class="attribute-value">248</span><span>, </span> </li> <li class="alt"> <span class="attribute">FIELD_TYPE_TINY_BLOB</span><span>=</span><span class="attribute-value">249</span><span>, </span> </li> <li> <span class="attribute">FIELD_TYPE_MEDIUM_BLOB</span><span>=</span><span class="attribute-value">250</span><span>, </span> </li> <li class="alt"> <span class="attribute">FIELD_TYPE_LONG_BLOB</span><span>=</span><span class="attribute-value">251</span><span>, </span> </li> <li> <span class="attribute">FIELD_TYPE_BLOB</span><span>=</span><span class="attribute-value">252</span><span>, </span> </li> <li class="alt"> <span class="attribute">FIELD_TYPE_VAR_STRING</span><span>=</span><span class="attribute-value">253</span><span>, </span> </li> <li> <span class="attribute">FIELD_TYPE_STRING</span><span>=</span><span class="attribute-value">254</span><span>, </span> </li> <li class="alt"> <span class="attribute">FIELD_TYPE_GEOMETRY</span><span>=</span><span class="attribute-value">255</span><span> </span> </li> <li><span>}; </span></li> <li class="alt"> <span>///</span><span class="tag"><span class="tag-name">summary</span><span class="tag">></span><span> </span></span> </li> <li><span>/// C prototypes warpper for MySQL(和PHP搭配之最佳组合)lib. </span></li> <li class="alt"> <span>///</span><span class="tag"></span><span class="tag-name">summary</span><span class="tag">></span><span> </span> </li> <li><span>internal class CPrototypes </span></li> <li class="alt"><span>{ </span></li> <li> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_init"</span><span> )] </span> </li> <li class="alt"><span>unsafe public static extern void* MySQL(和PHP搭配之最佳组合)_init(void* must_be_null); </span></li> <li> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_close"</span><span> )] </span> </li> <li class="alt"><span>unsafe public static extern void MySQL(和PHP搭配之最佳组合)_close(void* handle); </span></li> <li><span>// BEGIN ADDITION 2004-07-01 BY Alex Seewald </span></li> <li class="alt"><span>// Enables us to call MySQL(和PHP搭配之最佳组合)_option to activate compression and timeout </span></li> <li> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_options"</span><span> )] </span> </li> <li class="alt"><span>unsafe public static extern void MySQL(和PHP搭配之最佳组合)_options(void* MySQL(和PHP搭配之最佳组合), uint option, uint *value); </span></li> <li><span>// END ADDITION 2004-07-01 By Alex Seewald </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_real_connect"</span><span> )] </span> </li> <li><span>unsafe public static extern void* MySQL(和PHP搭配之最佳组合)_real_connect(void* MySQL(和PHP搭配之最佳组合), <br>string host, string user, string passwd, string db, uint port, string unix_socket, int client_flag); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_query"</span><span> )] </span> </li> <li><span>unsafe public static extern int MySQL(和PHP搭配之最佳组合)_query(void*MySQL(和PHP搭配之最佳组合), string query); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_store_result"</span><span> )] </span> </li> <li><span>unsafe public static extern void *MySQL(和PHP搭配之最佳组合)_store_result(void *MySQL(和PHP搭配之最佳组合)); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_free_result"</span><span> )] </span> </li> <li><span>unsafe public static extern void MySQL(和PHP搭配之最佳组合)_free_result(void*result); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_errno"</span><span> )] </span> </li> <li><span>unsafe public static extern uint MySQL(和PHP搭配之最佳组合)_errno(void*MySQL(和PHP搭配之最佳组合)); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_error"</span><span> )] </span> </li> <li><span>unsafe public static extern string MySQL(和PHP搭配之最佳组合)_error(void*MySQL(和PHP搭配之最佳组合)); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_field_count"</span><span> )] </span> </li> <li><span>unsafe public static extern uint MySQL(和PHP搭配之最佳组合)_field_count(void*MySQL(和PHP搭配之最佳组合)); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_affected_rows"</span><span> )] </span> </li> <li><span>unsafe public static extern ulong MySQL(和PHP搭配之最佳组合)_affected_rows(void*MySQL(和PHP搭配之最佳组合)); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_num_fields"</span><span> )] </span> </li> <li><span>unsafe public static extern uint MySQL(和PHP搭配之最佳组合)_num_fields(void*result); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_num_rows"</span><span> )] </span> </li> <li><span>unsafe public static extern ulong MySQL(和PHP搭配之最佳组合)_num_rows(void *result); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_fetch_field_direct"</span><span> )] </span> </li> <li><span>unsafe public static extern IntPtr MySQL(和PHP搭配之最佳组合)_fetch_field_direct(void*result, uint fieldnr); </span></li> <li class="alt"> <span>///</span><span class="tag"><span class="tag-name">returns</span><span class="tag">></span><span>Returns a string that represents the client library version</span><span class="tag"></span><span class="tag-name">returns</span><span class="tag">></span><span> </span></span> </li> <li> <span>[DllImport("libMySQL(和PHP搭配之最佳组合).dll",</span><span class="attribute">CharSet</span><span>=</span><span class="attribute-value">System</span><span>.Runtime.InteropServices.CharSet.Ansi, </span> </li> <li class="alt"> <span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_get_client_info"</span><span>, </span><span class="attribute">ExactSpelling</span><span>=</span><span class="attribute-value">true</span><span>)] </span> </li> <li><span>public static extern string GetClientInfo(); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_fetch_row"</span><span> )] </span> </li> <li><span>unsafe public static extern IntPtr MySQL(和PHP搭配之最佳组合)_fetch_row(void*result); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_select_db"</span><span> )] </span> </li> <li><span>unsafe public static extern int MySQL(和PHP搭配之最佳组合)_select_db(void*MySQL(和PHP搭配之最佳组合),string dbname); </span></li> <li class="alt"> <span>[ DllImport( "libMySQL(和PHP搭配之最佳组合).dll", </span><span class="attribute">EntryPoint</span><span>=</span><span class="attribute-value">"MySQL(和PHP搭配之最佳组合)_fetch_lengths"</span><span> )] </span> </li> <li><span>unsafe public static extern UInt32 *MySQL(和PHP搭配之最佳组合)_fetch_lengths(void*result); </span></li> <li class="alt"><span>} </span></li> <li><span>} </span></li> </ol>
基本上是将C风格的基础数据结构进行.net的重新定义,然后通过InteropServices进行访问。具体如何利用这个库进行操作,可以参考其中的例子。以上的相关内容就是对.NET如何访问MySQL数据库的介绍,望你能有所收获。