MySQL实际上有一个.net数据提供者,你可以考虑通过ODBC。 scott blood < SC ********* @ hotmail.com>在消息中写道 新闻:O%*************** @ TK2MSFTNGP10.phx.gbl ... Iain, 但是,您可以使用ODBC通过代码连接到MySQL,只要您知道要使用的ODBC连接字符串即可。请看下面的代码片段。 使用System.Data.Odbc; 使用System.Data; private void GetDataFromMySQL( ) {字符串connStr ="" ;; //我不确定MySql的连接字符串是什么,我认为它可能会 ; Provider = MySQLProv; Data Source = mydb; User Id = UserName; Password = asdasd;" using(OdbcConnection odbcCon = new OdbcConnection(connStr))使用( OdbcCommand odbcCom = new OdbcCommand(" Select * From Product", odbcCon))使用(OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom))使用(DataSet ds = new DataSet()) {odbcCon.Open(); odbcDA.Fill(ds); / **现在我们在DataSet中拥有它,我们可以用它做你想做的事:你的控件...... ** / this.dataGridView1.DataSource = ds.Tables [0]; } } 希望这有帮助 问候 Sc ott Blood C#开发商 " Iain" < TE ** @ test.co.uk>在消息中写道新闻:eF **************** @ TK2MSFTNGP09.phx.gbl ... 嗨 TIA Iain " scott blood" < SC ********* @ hotmail.com>在消息中写道 新闻:O%*************** @ TK2MSFTNGP10.phx.gbl ... 但是,你可以使用ODBC通过代码连接到MySQL ...? http://dev.mysql.com/downloads/connector/net/1.0.html HiIs it possible to get Visual Studio C# Express (beta 2) connecting to aMySQL database?TIAIain 解决方案 Iain,Unfortunatly you cannot visually connect to MySQL through C# Express, i dontknow why, i think this is just one of the limitations of C# Express.However, you can use ODBC to connect to MySQL through code, so long as youknow the ODBC Connection string to use. Please have a look at the followingcode snippet.using System.Data.Odbc;using System.Data;private void GetDataFromMySQL(){string connStr = "";// i am not sure what the connection string for MySql would be, i think itmight "Provider=MySQLProv;Data Source=mydb;UserId=UserName;Password=asdasd;"using (OdbcConnection odbcCon = new OdbcConnection(connStr))using (OdbcCommand odbcCom = new OdbcCommand("Select * From Product",odbcCon))using (OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom))using (DataSet ds = new DataSet()){odbcCon.Open();odbcDA.Fill(ds);/** Now that we have it in a DataSet, we can do what you want with it: fyour controls...**/this.dataGridView1.DataSource = ds.Tables[0];}}Hope this helpsRegardsScott BloodC# Developer"Iain" <te**@test.co.uk> wrote in messagenews:eF****************@TK2MSFTNGP09.phx.gbl... Hi Is it possible to get Visual Studio C# Express (beta 2) connecting to a MySQL database? TIA IainMySQL actually have a .net data provider, you could consider this over ODBC."scott blood" <sc*********@hotmail.com> wrote in messagenews:O%***************@TK2MSFTNGP10.phx.gbl... Iain, Unfortunatly you cannot visually connect to MySQL through C# Express, i dont know why, i think this is just one of the limitations of C# Express. However, you can use ODBC to connect to MySQL through code, so long as you know the ODBC Connection string to use. Please have a look at the following code snippet. using System.Data.Odbc; using System.Data; private void GetDataFromMySQL() { string connStr = ""; // i am not sure what the connection string for MySql would be, i think it might "Provider=MySQLProv;Data Source=mydb;User Id=UserName;Password=asdasd;" using (OdbcConnection odbcCon = new OdbcConnection(connStr)) using (OdbcCommand odbcCom = new OdbcCommand("Select * From Product", odbcCon)) using (OdbcDataAdapter odbcDA = new OdbcDataAdapter(odbcCom)) using (DataSet ds = new DataSet()) { odbcCon.Open(); odbcDA.Fill(ds); /** Now that we have it in a DataSet, we can do what you want with it: f your controls... **/ this.dataGridView1.DataSource = ds.Tables[0]; } } Hope this helps Regards Scott Blood C# Developer "Iain" <te**@test.co.uk> wrote in message news:eF****************@TK2MSFTNGP09.phx.gbl... Hi Is it possible to get Visual Studio C# Express (beta 2) connecting to a MySQL database? TIA Iain"scott blood" <sc*********@hotmail.com> wrote in messagenews:O%***************@TK2MSFTNGP10.phx.gbl... However, you can use ODBC to connect to MySQL through codeYes you can, but why on earth would you want to use ODBC (or even OleDB)when MySQL provide an excellent native .NET data provider...? http://dev.mysql.com/downloads/connector/net/1.0.html 这篇关于Visual Studio C#Express - MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-31 08:44