c#怎么连接mysql数据库

2024-11-27 16:29:17
推荐回答(1个)
回答(1):

string ConnectionString = ConfigurationManager.AppSettings["ConnectionString"];
string sqlString="......(此处sql语句省略)";
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand(sqlString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();//执行sql语句
return rows;
}
catch (MySql.Data.MySqlClient.MySqlException e)
{
connection.Close();
throw e;
}
}
}