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