找传奇、传世资源到传世资源站!

c#操作mysql数据库CRUD操作

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

c#操作mysql数据库 CRUDc#操作mysql数据库CRUD操作 C#数据库操作-第1张class SqlHelper { //返回链接数据库的字符串 public static string ConnString { get { return "Data Source='localhost';Database='dbdemo';User Id='root';Password='wdf123';charset='utf8'"; } } /// <summary> /// sqlserver 执行通用的添加,修改,删除操作 /// </summary> /// <param name="sql">insert/update/delete语句</param> /// <param name="pars">参数类型的数组</param> /// <returns>int 受影响的条数</returns> public static int mssql_exec(string sql,SqlParameter[] pars) { SqlConnection conn = new SqlConnection(ConnString); try { if (conn.State == ConnectionState.Closed) { conn.Open(); } SqlCommand cmd = new SqlCommand(sql, conn); if (pars != null && pars.Length > 0) { foreach (SqlParameter p in pars) { cmd.Parameters.Add(p); } } int count = cmd.ExecuteNonQuery(); return count; }catch(Exception ex){ throw ex; //return 0; } finally { conn.Close(); } } /// <summary> /// sqlserver 执行通用的添加,修改,删除操作 /// </summary> /// <param name="sql">insert/update/delete语句</param> /// <param name="pars">参数类型的数组</param> /// <returns>int 受影响的条数</returns> public static int mysql_exec(string sql, MySqlParameter[] pars) { MySqlConnection conn = new MySqlConnection(ConnString); try { if (conn.State == ConnectionState.Closed) { conn.Open(); } MySqlCommand cmd = new MySqlCommand(sql, conn); if (pars != null && pars.Length > 0) { foreach (MySqlParameter p in pars) { cmd.Parameters.Add(p); } } int count = cmd.ExecuteNonQuery(); return count; } catch (Exception ex) { throw ex; //return 0; } finally { conn.Close(); } }

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复