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

            strSql.Append("update Publishers set ");

            strSql.Append("Id=@Id,");
            strSql.Append("Name=@Name");
            strSql.Append(" where Id=@Id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Id",   SqlDbType.Int,      4),
                new SqlParameter("@Name", SqlDbType.NVarChar, 200)
            };
            parameters[0].Value = model.Id;
            parameters[1].Value = model.Name;

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

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

            strSql.Append("insert into Publishers(");
            strSql.Append("Name)");
            strSql.Append(" values (");
            strSql.Append("@Name)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Name", SqlDbType.NVarChar, 200)
            };
            parameters[0].Value = model.Name;

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

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

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

            Model.Publishers model = new Model.Publishers();
            DataSet          ds    = DbHelperSQL.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                return(DataRowToModel(ds.Tables[0].Rows[0]));
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.Publishers model)
 {
     return(dal.Update(model));
 }
Exemple #6
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int Add(Model.Publishers model)
 {
     return(dal.Add(model));
 }