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

            strSql.Append("update TcChanpin set ");
            strSql.Append("Articleid=@Articleid,");
            strSql.Append("Shuxing=@Shuxing,");
            strSql.Append("Addtime=@Addtime");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Articleid", SqlDbType.Int,       4),
                new SqlParameter("@Shuxing",   SqlDbType.NText),
                new SqlParameter("@Addtime",   SqlDbType.DateTime),
                new SqlParameter("@ID",        SqlDbType.Int, 4)
            };
            parameters[0].Value = model.Articleid;
            parameters[1].Value = model.Shuxing;
            parameters[2].Value = model.Addtime;
            parameters[3].Value = model.ID;

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

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

            strSql.Append("insert into TcChanpin(");
            strSql.Append("Articleid,Shuxing,Addtime)");
            strSql.Append(" values (");
            strSql.Append("@Articleid,@Shuxing,@Addtime)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Articleid", SqlDbType.Int,    4),
                new SqlParameter("@Shuxing",   SqlDbType.NText),
                new SqlParameter("@Addtime",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.Articleid;
            parameters[1].Value = model.Shuxing;
            parameters[2].Value = model.Addtime;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
示例#3
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Tc.Model.TcChanpin model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into TcChanpin(");
            strSql.Append("Articleid,Shuxing,Addtime)");
            strSql.Append(" values (");
            strSql.Append("@Articleid,@Shuxing,@Addtime)");
            SqlParameter[] parameters =
            {
                new SqlParameter("@Articleid", SqlDbType.Int,     4),
                new SqlParameter("@Shuxing",   SqlDbType.VarChar, 0),
                new SqlParameter("@Addtime",   SqlDbType.Date)
            };
            parameters[0].Value = model.Articleid;
            parameters[1].Value = model.Shuxing;
            parameters[2].Value = model.Addtime;

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

            if (rows > 0)
            {
                return(GetMaxId());
            }
            else
            {
                return(0);
            }
        }
示例#4
0
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Tc.Model.TcChanpin DataRowToModel(DataRow row)
 {
     Tc.Model.TcChanpin model = new Tc.Model.TcChanpin();
     if (row != null)
     {
         if (row["ID"] != null && row["ID"].ToString() != "")
         {
             model.ID = int.Parse(row["ID"].ToString());
         }
         if (row["Articleid"] != null && row["Articleid"].ToString() != "")
         {
             model.Articleid = int.Parse(row["Articleid"].ToString());
         }
         if (row["Shuxing"] != null)
         {
             model.Shuxing = row["Shuxing"].ToString();
         }
         if (row["Addtime"] != null && row["Addtime"].ToString() != "")
         {
             model.Addtime = DateTime.Parse(row["Addtime"].ToString());
         }
     }
     return(model);
 }
示例#5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Tc.Model.TcChanpin GetModel(int ID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 ID,Articleid,Shuxing,Addtime from TcChanpin ");
            strSql.Append(" where ID=@ID");
            SqlParameter[] parameters =
            {
                new SqlParameter("@ID", SqlDbType.Int, 4)
            };
            parameters[0].Value = ID;

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

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