/// <summary> /// 得到一个对象实体 /// </summary> public LYSC.CompanyWeb.Model.HKSJ_Main GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 ID,title,content,type,Date,people,picUrl from HKSJ_Main "); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = ID; LYSC.CompanyWeb.Model.HKSJ_Main model = new LYSC.CompanyWeb.Model.HKSJ_Main(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ID"] != null && ds.Tables[0].Rows[0]["ID"].ToString() != "") { model.ID = int.Parse(ds.Tables[0].Rows[0]["ID"].ToString()); } if (ds.Tables[0].Rows[0]["title"] != null && ds.Tables[0].Rows[0]["title"].ToString() != "") { model.title = ds.Tables[0].Rows[0]["title"].ToString(); } if (ds.Tables[0].Rows[0]["content"] != null && ds.Tables[0].Rows[0]["content"].ToString() != "") { model.content = ds.Tables[0].Rows[0]["content"].ToString(); } if (ds.Tables[0].Rows[0]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "") { model.type = ds.Tables[0].Rows[0]["type"].ToString(); } if (ds.Tables[0].Rows[0]["Date"] != null && ds.Tables[0].Rows[0]["Date"].ToString() != "") { model.Date = DateTime.Parse(ds.Tables[0].Rows[0]["Date"].ToString()); } if (ds.Tables[0].Rows[0]["people"] != null && ds.Tables[0].Rows[0]["people"].ToString() != "") { model.people = ds.Tables[0].Rows[0]["people"].ToString(); } if (ds.Tables[0].Rows[0]["picUrl"] != null && ds.Tables[0].Rows[0]["picUrl"].ToString() != "") { model.picUrl = ds.Tables[0].Rows[0]["picUrl"].ToString(); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(LYSC.CompanyWeb.Model.HKSJ_Main model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update HKSJ_Main set "); strSql.Append("title=@title,"); strSql.Append("content=@content,"); strSql.Append("type=@type,"); strSql.Append("Date=@Date,"); strSql.Append("people=@people,"); strSql.Append("picUrl=@picUrl"); strSql.Append(" where ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.VarChar, 200), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@type", SqlDbType.Char, 8), new SqlParameter("@Date", SqlDbType.DateTime), new SqlParameter("@people", SqlDbType.VarChar, 20), new SqlParameter("@picUrl", SqlDbType.VarChar, 250), new SqlParameter("@ID", SqlDbType.Int, 4) }; parameters[0].Value = model.title; parameters[1].Value = model.content; parameters[2].Value = model.type; parameters[3].Value = model.Date; parameters[4].Value = model.people; parameters[5].Value = model.picUrl; parameters[6].Value = model.ID; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(LYSC.CompanyWeb.Model.HKSJ_Main model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into HKSJ_Main("); strSql.Append("title,content,type,Date,people,picUrl)"); strSql.Append(" values ("); strSql.Append("@title,@content,@type,@Date,@people,@picUrl)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@title", SqlDbType.VarChar, 200), new SqlParameter("@content", SqlDbType.NText), new SqlParameter("@type", SqlDbType.Char, 8), new SqlParameter("@Date", SqlDbType.DateTime), new SqlParameter("@people", SqlDbType.VarChar, 20), new SqlParameter("@picUrl", SqlDbType.VarChar, 250) }; parameters[0].Value = model.title; parameters[1].Value = model.content; parameters[2].Value = model.type; parameters[3].Value = model.Date; parameters[4].Value = model.people; parameters[5].Value = model.picUrl; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }