/// <summary> /// 增加一条数据 /// </summary> public int Add(LearnSite.Model.Flection model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into Flection("); strSql.Append("Fcid,Fhid,Fcontent,Fdate)"); strSql.Append(" values ("); strSql.Append("@Fcid,@Fhid,@Fcontent,@Fdate)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Fcid", SqlDbType.Int, 4), new SqlParameter("@Fhid", SqlDbType.Int, 4), new SqlParameter("@Fcontent", SqlDbType.NText), new SqlParameter("@Fdate", SqlDbType.DateTime) }; parameters[0].Value = model.Fcid; parameters[1].Value = model.Fhid; parameters[2].Value = model.Fcontent; parameters[3].Value = model.Fdate; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(LearnSite.Model.Flection model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update Flection set "); strSql.Append("Fcontent=@Fcontent"); strSql.Append(" where Fcid=@Fcid "); SqlParameter[] parameters = { new SqlParameter("@Fcid", SqlDbType.Int, 4), new SqlParameter("@Fcontent", SqlDbType.NText) }; parameters[0].Value = model.Fcid; parameters[1].Value = model.Fcontent; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public LearnSite.Model.Flection GetModel(int Fcid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Fid,Fcid,Fhid,Fcontent,Fdate from Flection "); strSql.Append(" where Fcid=@Fcid "); SqlParameter[] parameters = { new SqlParameter("@Fcid", SqlDbType.Int, 4) }; parameters[0].Value = Fcid; LearnSite.Model.Flection model = new LearnSite.Model.Flection(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Fid"].ToString() != "") { model.Fid = int.Parse(ds.Tables[0].Rows[0]["Fid"].ToString()); } if (ds.Tables[0].Rows[0]["Fcid"].ToString() != "") { model.Fcid = int.Parse(ds.Tables[0].Rows[0]["Fcid"].ToString()); } if (ds.Tables[0].Rows[0]["Fhid"].ToString() != "") { model.Fhid = int.Parse(ds.Tables[0].Rows[0]["Fhid"].ToString()); } model.Fcontent = ds.Tables[0].Rows[0]["Fcontent"].ToString(); if (ds.Tables[0].Rows[0]["Fdate"].ToString() != "") { model.Fdate = DateTime.Parse(ds.Tables[0].Rows[0]["Fdate"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// �õ�һ������ʵ�� /// </summary> public LearnSite.Model.Flection GetModel(int Fcid) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Fid,Fcid,Fhid,Fcontent,Fdate from Flection "); strSql.Append(" where Fcid=@Fcid "); SqlParameter[] parameters = { new SqlParameter("@Fcid", SqlDbType.Int,4)}; parameters[0].Value = Fcid; LearnSite.Model.Flection model = new LearnSite.Model.Flection(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["Fid"].ToString() != "") { model.Fid = int.Parse(ds.Tables[0].Rows[0]["Fid"].ToString()); } if (ds.Tables[0].Rows[0]["Fcid"].ToString() != "") { model.Fcid = int.Parse(ds.Tables[0].Rows[0]["Fcid"].ToString()); } if (ds.Tables[0].Rows[0]["Fhid"].ToString() != "") { model.Fhid = int.Parse(ds.Tables[0].Rows[0]["Fhid"].ToString()); } model.Fcontent = ds.Tables[0].Rows[0]["Fcontent"].ToString(); if (ds.Tables[0].Rows[0]["Fdate"].ToString() != "") { model.Fdate = DateTime.Parse(ds.Tables[0].Rows[0]["Fdate"].ToString()); } return model; } else { return null; } }