/// <summary> /// 更新一条数据 /// </summary> public bool Update(DiDaJiangCheng.Model.tbClassInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update tbClassInfo set "); strSql.Append(" ClassName = @ClassName , "); strSql.Append(" SpecialtyId = @SpecialtyId , "); strSql.Append(" classroomId = @classroomId , "); strSql.Append(" eductionalSystem = @eductionalSystem , "); strSql.Append(" enterTime = @enterTime , "); strSql.Append(" Marks = @Marks "); strSql.Append(" where ClassId=@ClassId "); SqlParameter[] parameters = { new SqlParameter("@ClassId", SqlDbType.Int, 4), new SqlParameter("@ClassName", SqlDbType.NVarChar, 50), new SqlParameter("@SpecialtyId", SqlDbType.Int, 4), new SqlParameter("@classroomId", SqlDbType.NVarChar, 50), new SqlParameter("@eductionalSystem", SqlDbType.NVarChar, 50), new SqlParameter("@enterTime", SqlDbType.Date, 3), new SqlParameter("@Marks", SqlDbType.NVarChar, -1) }; parameters[0].Value = model.ClassId; parameters[1].Value = model.ClassName; parameters[2].Value = model.SpecialtyId; parameters[3].Value = model.classroomId; parameters[4].Value = model.eductionalSystem; parameters[5].Value = model.enterTime; parameters[6].Value = model.Marks; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public DiDaJiangCheng.Model.tbClassInfo GetModel(int ClassId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select ClassId, ClassName, SpecialtyId, classroomId, eductionalSystem, enterTime, Marks "); strSql.Append(" from tbClassInfo "); strSql.Append(" where ClassId=@ClassId"); SqlParameter[] parameters = { new SqlParameter("@ClassId", SqlDbType.Int, 4) }; parameters[0].Value = ClassId; DiDaJiangCheng.Model.tbClassInfo model = new DiDaJiangCheng.Model.tbClassInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["ClassId"].ToString() != "") { model.ClassId = int.Parse(ds.Tables[0].Rows[0]["ClassId"].ToString()); } model.ClassName = ds.Tables[0].Rows[0]["ClassName"].ToString(); if (ds.Tables[0].Rows[0]["SpecialtyId"].ToString() != "") { model.SpecialtyId = int.Parse(ds.Tables[0].Rows[0]["SpecialtyId"].ToString()); } model.classroomId = ds.Tables[0].Rows[0]["classroomId"].ToString(); model.eductionalSystem = ds.Tables[0].Rows[0]["eductionalSystem"].ToString(); if (ds.Tables[0].Rows[0]["enterTime"].ToString() != "") { model.enterTime = DateTime.Parse(ds.Tables[0].Rows[0]["enterTime"].ToString()); } model.Marks = ds.Tables[0].Rows[0]["Marks"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(DiDaJiangCheng.Model.tbClassInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into tbClassInfo("); strSql.Append("ClassName,SpecialtyId,classroomId,eductionalSystem,enterTime,Marks"); strSql.Append(") values ("); strSql.Append("@ClassName,@SpecialtyId,@classroomId,@eductionalSystem,@enterTime,@Marks"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@ClassName", SqlDbType.NVarChar, 50), new SqlParameter("@SpecialtyId", SqlDbType.Int, 4), new SqlParameter("@classroomId", SqlDbType.NVarChar, 50), new SqlParameter("@eductionalSystem", SqlDbType.NVarChar, 50), new SqlParameter("@enterTime", SqlDbType.Date, 3), new SqlParameter("@Marks", SqlDbType.NVarChar, -1) }; parameters[0].Value = model.ClassName; parameters[1].Value = model.SpecialtyId; parameters[2].Value = model.classroomId; parameters[3].Value = model.eductionalSystem; parameters[4].Value = model.enterTime; parameters[5].Value = model.Marks; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }