/// <summary> /// 更新一条数据 /// </summary> public bool Update(M_city model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update city set "); strSql.Append("cityID=@cityID,"); strSql.Append("city=@city,"); strSql.Append("fatherID=@fatherID"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@cityID", SqlDbType.Int, 4), new SqlParameter("@city", SqlDbType.VarChar, 200), new SqlParameter("@fatherID", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.cityID; parameters[1].Value = model.city; parameters[2].Value = model.fatherID; parameters[3].Value = model.id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(M_city model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into city("); strSql.Append("cityID,city,fatherID)"); strSql.Append(" values ("); strSql.Append("@cityID,@city,@fatherID)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@cityID", SqlDbType.Int, 4), new SqlParameter("@city", SqlDbType.VarChar, 200), new SqlParameter("@fatherID", SqlDbType.Int, 4) }; parameters[0].Value = model.cityID; parameters[1].Value = model.city; parameters[2].Value = model.fatherID; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public M_city DataRowToModel(DataRow row) { M_city model = new M_city(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["cityID"] != null && row["cityID"].ToString() != "") { model.cityID = int.Parse(row["cityID"].ToString()); } if (row["city"] != null) { model.city = row["city"].ToString(); } if (row["fatherID"] != null && row["fatherID"].ToString() != "") { model.fatherID = int.Parse(row["fatherID"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public M_city GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,cityID,city,fatherID from city "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; M_city model = new M_city(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(M_city model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(M_city model) { return(dal.Add(model)); }