public class SqlHelpe
{
/// <summary>
/// 建立mysql数据库链接
/// </summary>
/// <returns></returns>
public static MySqlConnection getMySqlCon()
{
// string conn = "Data Source=localhost;User ID=root;Password=123;DataBase=googlesearch;Charset=gbk;";
string conn = "Data Source=192.168.10.80;User ID=admin;Password=admin123;DataBase=googlesearch;Charset=gbk;";
MySqlConnection con = new MySqlConnection(conn);
con.Open();
return con;
}
/// <summary>
/// 建立执行命令语句对象
/// </summary>
/// <param name="sql"></param>
/// <param name="mysql"></param>
/// <returns></returns>
public static MySqlCommand getSqlCommand(String sql, MySqlConnection mysql)
{
MySqlCommand cmd = new MySqlCommand(sql, mysql);
return cmd;
}
public static int ExecuteNonQuery(string sql, MySqlParameter[] pars)
{
MySqlConnection conn = getMySqlCon();
MySqlCommand comm = new MySqlCommand(sql, conn);
if (pars != null)
{
foreach (MySqlParameter p in pars)
comm.Parameters.AddWithValue