コード例 #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(dbamet.Model.ActiveIntro model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into ActiveIntro(");
            strSql.Append("type,content,modifytime)");
            strSql.Append(" values (");
            strSql.Append("@type,@content,@modifytime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@type",       SqlDbType.VarChar, 50),
                new SqlParameter("@content",    SqlDbType.VarChar, 50),
                new SqlParameter("@modifytime", SqlDbType.DateTime)
            };
            parameters[0].Value = model.type;
            parameters[1].Value = model.content;
            parameters[2].Value = model.modifytime;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
コード例 #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(dbamet.Model.ActiveIntro model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update ActiveIntro set ");
            strSql.Append("type=@type,");
            strSql.Append("content=@content,");
            strSql.Append("modifytime=@modifytime");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@type",       SqlDbType.VarChar,   50),
                new SqlParameter("@content",    SqlDbType.VarChar,   50),
                new SqlParameter("@modifytime", SqlDbType.DateTime),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.type;
            parameters[1].Value = model.content;
            parameters[2].Value = model.modifytime;
            parameters[3].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #3
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public dbamet.Model.ActiveIntro GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 id,type,content,modifytime from ActiveIntro ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;

            dbamet.Model.ActiveIntro model = new dbamet.Model.ActiveIntro();
            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]["type"] != null && ds.Tables[0].Rows[0]["type"].ToString() != "")
                {
                    model.type = ds.Tables[0].Rows[0]["type"].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]["modifytime"] != null && ds.Tables[0].Rows[0]["modifytime"].ToString() != "")
                {
                    model.modifytime = DateTime.Parse(ds.Tables[0].Rows[0]["modifytime"].ToString());
                }
                return(model);
            }
            else
            {
                return(null);
            }
        }