c#与mysql的连接
作者:
c#与mysql的连接
不只是c#,其实是说.NET下与mysql的连接,如果一般说来,因为.NET没有相应的驱动连接与其对应,是用odbc的连接,但这样的弊端是显而易见的,在sourceforge上有个开源的项目,具体下载地址是
http://prdownloads.sourceforge.net/mysqldrivercs/MySQLDriverCS-n-EasyQueryTools-3.0.18.exe?use_mirror=jaist
方法如下:
using MySQLDriverCS;
MySQLConnection conn = new MySQLConnection( new MySQLConnectionString("localhost","test","root","").AsString );
conn.Open();
如果你使用的是.net的集成开发环境(visual studio.net)那么在代码中输入MySQLDriverCS后再输入一个”.”就可以看到MySQLDriverCS名称空间中的所有的东西了.
下面是commond:
MySQLCommand cmd;
cmd = new MySQLDriverCS.MySQLCommand("Drop TABLE IF EXISTS test.mysqldrivercs_test",conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = new MySQLDriverCS.MySQLCommand("Create TABLE test.mysqldrivercs_test("+
"SettingID tinyint(3) unsigned NOT NULL auto_increment,"+
"SettingValue text, "+
"PRIMARY KEY (SettingID), UNIQUE KEY SettingID(SettingID), KEY SettingID_2 (SettingID))"+
" TYPE=MyISAM COMMENT=''''MySQL test table''''",conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
用过之后发现还是比较好用的
http://prdownloads.sourceforge.net/mysqldrivercs/MySQLDriverCS-n-EasyQueryTools-3.0.18.exe?use_mirror=jaist
方法如下:
using MySQLDriverCS;
MySQLConnection conn = new MySQLConnection( new MySQLConnectionString("localhost","test","root","").AsString );
conn.Open();
如果你使用的是.net的集成开发环境(visual studio.net)那么在代码中输入MySQLDriverCS后再输入一个”.”就可以看到MySQLDriverCS名称空间中的所有的东西了.
下面是commond:
MySQLCommand cmd;
cmd = new MySQLDriverCS.MySQLCommand("Drop TABLE IF EXISTS test.mysqldrivercs_test",conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
cmd = new MySQLDriverCS.MySQLCommand("Create TABLE test.mysqldrivercs_test("+
"SettingID tinyint(3) unsigned NOT NULL auto_increment,"+
"SettingValue text, "+
"PRIMARY KEY (SettingID), UNIQUE KEY SettingID(SettingID), KEY SettingID_2 (SettingID))"+
" TYPE=MyISAM COMMENT=''''MySQL test table''''",conn);
cmd.ExecuteNonQuery();
cmd.Dispose();
用过之后发现还是比较好用的