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