使用asp.net连接到MySQL数据库 [英] Connecting to a mySQL database using asp.net
问题描述
所以经过一番尝试,我发现我需要一个驱动程序.我已经从下面的链接安装了组件.但是当我尝试添加SQL引用时仍然找不到任何SQL引用吗?我想知道是否有人会知道原因?我刚开始是asp.net.我发现了一些其他有关连接代码的问题,但是找不到以前在连接器/组件方面遇到过麻烦的人吗?
So after some tries I figured out I needed a driver for this. I've installed the Components from the links below. But I still can't find any SQL references when I try to add them? I'm wondering if anyone would know the reason for this? I just started with asp.net. I've found several other questions regarding code for connecting but I can't find anyone who've had trouble with the Connector/components before?
MYSQL连接器 http://dev.mysql.com/downloads/connector/net/5.0.html
MYSQL connector http://dev.mysql.com/downloads/connector/net/5.0.html
Microsoft数据访问组件(MDAC)2.8 http://www.microsoft .com/downloads/details.aspx?FamilyID = 6c050fe3-c795-4b7d-b037-185d0506396c& displaylang = zh-CN
Microsoft Data Access Components (MDAC) 2.8 http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en
我正在使用Visual Studio.
I am using Visual Studio.
推荐答案
右键单击引用",然后选择添加引用".浏览并选择Mysql.Data.dll
.
Right click on References, then select "Add Reference". Browse and select Mysql.Data.dll
.
该dll应该在您下载的连接器的安装目录中找到.
The dll should be found in the installation directory of the connector you downloaded.
最后,在代码中:
using MySql.Data.MySqlClient;
并且,示例连接:
MySqlConnection connection = new MySqlConnection("Database=database_name;Data Source=server_domain_or_ip;User Id=mysql_user;Password=mysql_password");
connection.Open();
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from mytable";
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//reader.GetString(0)
//reader["column_name"].ToString()
}
reader.Close();
这篇关于使用asp.net连接到MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!