Exemplo n.º 1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Shop.Model.SmallClass model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update t_smallClass set ");
            strSql.Append("smallname=@smallname,");
            strSql.Append("smallsort=@smallsort,");
            strSql.Append("bigname=@bigname,");
            strSql.Append("bigid=@bigid");
            strSql.Append(" where smallid=@smallid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@smallname", SqlDbType.VarChar, 20),
                new SqlParameter("@smallsort", SqlDbType.Int,      4),
                new SqlParameter("@bigname",   SqlDbType.VarChar, 20),
                new SqlParameter("@smallid",   SqlDbType.Int,      4),
                new SqlParameter("@bigid",     SqlDbType.Int, 4)
            };
            parameters[0].Value = model.smallname;
            parameters[1].Value = model.smallsort;
            parameters[2].Value = model.bigname;
            parameters[3].Value = model.smallid;
            parameters[4].Value = model.bigid;

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

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Shop.Model.SmallClass DataRowToModel(DataRow row)
 {
     Shop.Model.SmallClass model = new Shop.Model.SmallClass();
     if (row != null)
     {
         if (row["smallid"] != null && row["smallid"].ToString() != "")
         {
             model.smallid = int.Parse(row["smallid"].ToString());
         }
         if (row["bigid"] != null && row["bigid"].ToString() != "")
         {
             model.bigid = int.Parse(row["bigid"].ToString());
         }
         if (row["smallname"] != null)
         {
             model.smallname = row["smallname"].ToString();
         }
         if (row["smallsort"] != null && row["smallsort"].ToString() != "")
         {
             model.smallsort = int.Parse(row["smallsort"].ToString());
         }
         if (row["bigname"] != null)
         {
             model.bigname = row["bigname"].ToString();
         }
     }
     return(model);
 }
Exemplo n.º 3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Shop.Model.SmallClass model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into t_smallClass(");
            strSql.Append("bigid,smallname,smallsort,bigname)");
            strSql.Append(" values (");
            strSql.Append("@bigid,@smallname,@smallsort,@bigname)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@bigid",     SqlDbType.Int,      4),
                new SqlParameter("@smallname", SqlDbType.VarChar, 20),
                new SqlParameter("@smallsort", SqlDbType.Int,      4),
                new SqlParameter("@bigname",   SqlDbType.VarChar, 20)
            };
            parameters[0].Value = model.bigid;
            parameters[1].Value = model.smallname;
            parameters[2].Value = model.smallsort;
            parameters[3].Value = model.bigname;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Shop.Model.SmallClass GetModel(int smallid)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 smallid,bigid,smallname,smallsort,bigname from t_smallClass ");
            strSql.Append(" where smallid=@smallid");
            SqlParameter[] parameters =
            {
                new SqlParameter("@smallid", SqlDbType.Int, 4)
            };
            parameters[0].Value = smallid;

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

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