C# 连接Mysql读写

static string connstr = "server=127.0.0.1;port=3306;database=newim;user=admin;password=admin;";
MySqlConnection conn = new MySqlConnection(connstr);

读取:

public MySqlDataReader MYSQLReader(string sql)
{
conn.Open();


MySqlCommand cmd = new MySqlCommand(sql, conn);
try
{
MySqlDataReader reader = cmd.ExecuteReader();
return reader;
}
catch
{
return null;
}

}

 

执行写入:

public int MysqlExecuteNonQuery(string sql)
{
try
{


MySqlCommand cmd = new MySqlCommand(sql, conn);
int result = cmd.ExecuteNonQuery();
return result;
}
catch (Exception e)
{
return -1;
}
}

 

C# 连接Mysql读写

上一篇:查找oracle数据库中的长事务


下一篇:mybatis: No enum constant org.apache.ibatis.type.JdbcType."VARCHAR"