c#怎么连接mysql数据库
展开全部
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;
}
}
}
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;
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |