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