Esempio n. 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(SP.Model.admin model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update admin set ");
            strSql.Append("pwd=@pwd");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@pwd", SqlDbType.VarChar, 100),
                new SqlParameter("@aid", SqlDbType.Int, 4)
            };

            parameters[0].Value = model.pwd;
            parameters[1].Value = model.aid;

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

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

            strSql.Append("insert into admin(");
            strSql.Append("lname,pwd,flag)");
            strSql.Append(" values (");
            strSql.Append("@lname,@pwd,@flag)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@lname", SqlDbType.VarChar,  50),
                new SqlParameter("@pwd",   SqlDbType.VarChar, 100),
                new SqlParameter("@flag",  SqlDbType.Int, 4)
            };
            parameters[0].Value = model.lname;
            parameters[1].Value = model.pwd;
            parameters[2].Value = model.flag;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public SP.Model.admin DataRowToModel(DataRow row)
 {
     SP.Model.admin model = new SP.Model.admin();
     if (row != null)
     {
         if (row["aid"] != null && row["aid"].ToString() != "")
         {
             model.aid = int.Parse(row["aid"].ToString());
         }
         if (row["lname"] != null)
         {
             model.lname = row["lname"].ToString();
         }
         if (row["pwd"] != null)
         {
             model.pwd = row["pwd"].ToString();
         }
         if (row["flag"] != null && row["flag"].ToString() != "")
         {
             model.flag = int.Parse(row["flag"].ToString());
         }
     }
     return(model);
 }
Esempio n. 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public SP.Model.admin GetModel(int aid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 aid,lname,pwd,flag from admin ");
            strSql.Append(" where aid=@aid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@aid", SqlDbType.Int, 4)
            };
            parameters[0].Value = aid;

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

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