/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.Bath model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update bath set "); strSql.Append("BathName=@BathName"); strSql.Append(" where BathId=@BathId"); MySqlParameter[] parameters = { new MySqlParameter("@BathName", MySqlDbType.VarChar, 255), new MySqlParameter("@BathId", MySqlDbType.Int32, 11) }; parameters[0].Value = model.BathName; parameters[1].Value = model.BathId; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Model.Bath model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into bath("); strSql.Append("BathName)"); strSql.Append(" values ("); strSql.Append("@BathName)"); MySqlParameter[] parameters = { new MySqlParameter("@BathName", MySqlDbType.VarChar, 255) }; parameters[0].Value = model.BathName; int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Bath DataRowToModel(DataRow row) { Model.Bath model = new Model.Bath(); if (row != null) { if (row["BathId"] != null && row["BathId"].ToString() != "") { model.BathId = int.Parse(row["BathId"].ToString()); } if (row["BathName"] != null) { model.BathName = row["BathName"].ToString(); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.Bath GetModel(int BathId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select BathId,BathName from bath "); strSql.Append(" where BathId=@BathId"); MySqlParameter[] parameters = { new MySqlParameter("@BathId", MySqlDbType.Int32) }; parameters[0].Value = BathId; Model.Bath model = new Model.Bath(); DataSet ds = DbHelperMySQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }