Download the ". Net&mono" version of MySQL connector on the MySQL website https://dev.mysql.com/downloads/connector/net.
Add references to all DLLs in the V4 folder in the C # Reference. V4 corresponds to ". NET FRAME4", select the corresponding ". NET FRAME" version in the properties in project.
In the first column of the program, add the "Using MySql.Data.MySqlClient;"
The connection code is shown below.
String str = "server=localhost; Database = PHP; Uid = root; PWD = Redhat ";
Try
{
msc = new mysqlconnection (str);
MSc. Open ();
if (MSC. state = = ConnectionState.Open)
{
MessageBox.Show ("Database is open");
}
}
Catch
{
MessageBox.Show ("Database is open error! ");
}
This article is from the "Diligent Pebble" blog, please make sure to keep this source http://littlestone.blog.51cto.com/7190541/1930040
How to connect to the MySQL database in C #