/// <summary> /// 更新一条数据 /// </summary> public bool Update(starweibo.Model.relationGroupInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update relationGroupInfo set "); strSql.Append("userId=@userId,"); strSql.Append("groupName=@groupName,"); strSql.Append("sortLevel=@sortLevel"); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@groupName", SqlDbType.NVarChar, 20), new SqlParameter("@sortLevel", SqlDbType.Int, 4), new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = model.userId; parameters[1].Value = model.groupName; parameters[2].Value = model.sortLevel; 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(starweibo.Model.relationGroupInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into relationGroupInfo("); strSql.Append("userId,groupName,sortLevel)"); strSql.Append(" values ("); strSql.Append("@userId,@groupName,@sortLevel)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@userId", SqlDbType.Int, 4), new SqlParameter("@groupName", SqlDbType.NVarChar, 20), new SqlParameter("@sortLevel", SqlDbType.Int, 4) }; parameters[0].Value = model.userId; parameters[1].Value = model.groupName; parameters[2].Value = model.sortLevel; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public starweibo.Model.relationGroupInfo DataRowToModel(DataRow row) { starweibo.Model.relationGroupInfo model = new starweibo.Model.relationGroupInfo(); if (row != null) { if (row["id"] != null && row["id"].ToString() != "") { model.id = int.Parse(row["id"].ToString()); } if (row["userId"] != null && row["userId"].ToString() != "") { model.userId = int.Parse(row["userId"].ToString()); } if (row["groupName"] != null) { model.groupName = row["groupName"].ToString(); } if (row["sortLevel"] != null && row["sortLevel"].ToString() != "") { model.sortLevel = int.Parse(row["sortLevel"].ToString()); } } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public starweibo.Model.relationGroupInfo GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 id,userId,groupName,sortLevel from relationGroupInfo "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; starweibo.Model.relationGroupInfo model = new starweibo.Model.relationGroupInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }