/// <summary> /// 增加一条数据 /// </summary> public bool Add(DingModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BBS.dbo.Ding ("); strSql.Append("UserId,TieZiId,CreateTime"); strSql.Append(") values ("); strSql.Append("@UserId,@TieZiId,@CreateTime"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@TieZiId", SqlDbType.Decimal, 9), new SqlParameter("@CreateTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.TieZiId; parameters[2].Value = model.CreateTime; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }
/// <summary> /// 得到一个对象实体 /// </summary> public DingModel GetModel(string UserId, decimal TieZiId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select UserId, TieZiId, CreateTime "); strSql.Append(" from BBS.dbo.Ding "); strSql.Append(" where UserId=@UserId and TieZiId=@TieZiId "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@TieZiId", SqlDbType.Decimal, 9) }; parameters[0].Value = UserId; parameters[1].Value = TieZiId; DingModel model = new DingModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.UserId = ds.Tables[0].Rows[0]["UserId"].ToString(); if (ds.Tables[0].Rows[0]["TieZiId"].ToString() != "") { model.TieZiId = decimal.Parse(ds.Tables[0].Rows[0]["TieZiId"].ToString()); } if (ds.Tables[0].Rows[0]["CreateTime"].ToString() != "") { model.CreateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString()); } return(model); } else { return(model); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DingModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update BBS.dbo.Ding set "); strSql.Append(" UserId = @UserId , "); strSql.Append(" TieZiId = @TieZiId , "); strSql.Append(" CreateTime = @CreateTime "); strSql.Append(" where UserId=@UserId and TieZiId=@TieZiId "); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@TieZiId", SqlDbType.Decimal, 9), new SqlParameter("@CreateTime", SqlDbType.DateTime) }; parameters[0].Value = model.UserId; parameters[1].Value = model.TieZiId; parameters[2].Value = model.CreateTime; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }