Exemple #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(cn.itcast.bookshop.Model.BookComment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BookComment set ");
            strSql.Append("Msg=@Msg,");
            strSql.Append("CreateDateTime=@CreateDateTime,");
            strSql.Append("BookId=@BookId");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Msg",            SqlDbType.NVarChar,  -1),
                new SqlParameter("@CreateDateTime", SqlDbType.DateTime),
                new SqlParameter("@BookId",         SqlDbType.Int,        4),
                new SqlParameter("@Id",             SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Msg;
            parameters[1].Value = model.CreateDateTime;
            parameters[2].Value = model.BookId;
            parameters[3].Value = model.Id;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(cn.itcast.bookshop.Model.BookComment model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BookComment(");
            strSql.Append("Msg,CreateDateTime,BookId)");
            strSql.Append(" values (");
            strSql.Append("@Msg,@CreateDateTime,@BookId)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Msg",            SqlDbType.NVarChar,  -1),
                new SqlParameter("@CreateDateTime", SqlDbType.DateTime),
                new SqlParameter("@BookId",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Msg;
            parameters[1].Value = model.CreateDateTime;
            parameters[2].Value = model.BookId;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemple #3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public cn.itcast.bookshop.Model.BookComment DataRowToModel(DataRow row)
 {
     cn.itcast.bookshop.Model.BookComment model = new cn.itcast.bookshop.Model.BookComment();
     if (row != null)
     {
         if (row["Id"] != null && row["Id"].ToString() != "")
         {
             model.Id = int.Parse(row["Id"].ToString());
         }
         if (row["Msg"] != null)
         {
             model.Msg = row["Msg"].ToString();
         }
         if (row["CreateDateTime"] != null && row["CreateDateTime"].ToString() != "")
         {
             model.CreateDateTime = DateTime.Parse(row["CreateDateTime"].ToString());
         }
         if (row["BookId"] != null && row["BookId"].ToString() != "")
         {
             model.BookId = int.Parse(row["BookId"].ToString());
         }
     }
     return(model);
 }
Exemple #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public cn.itcast.bookshop.Model.BookComment GetModel(int Id)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 Id,Msg,CreateDateTime,BookId from BookComment ");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id", SqlDbType.Int, 4)
            };
            parameters[0].Value = Id;

            cn.itcast.bookshop.Model.BookComment model = new cn.itcast.bookshop.Model.BookComment();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }