Exemplo n.º 1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Insert(Model.SectionLeader model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into [SectionLeader](");
            strSql.Append("PeopleId,SectionId,Ext1");
            strSql.Append(") values (");
            strSql.Append("@PeopleId,@SectionId,@Ext1");
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@PeopleId",  SqlDbType.Int,     4),
                new SqlParameter("@SectionId", SqlDbType.Int,     4),
                new SqlParameter("@Ext1",      SqlDbType.VarChar, 50)
            };

            parameters[0].Value = model.PeopleId;
            parameters[1].Value = model.SectionId;
            parameters[2].Value = model.Ext1;

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

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.SectionLeader model)
        {
            StringBuilder             strSql     = new StringBuilder();
            Collection <SqlParameter> parameters = new Collection <SqlParameter>

                                                       ();
            SqlParameter parameter = null;
            int          count     = 0;

            strSql.Append("update [SectionLeader] set ");
            parameter = new SqlParameter("@Id",

                                         SqlDbType.Int, 4);
            parameter.Value = model.Id;
            parameters.Add(parameter);



            if (model.PeopleId_IsEdit)
            {
                strSql.Append(" PeopleId = @PeopleId,");
                parameter = new SqlParameter("@PeopleId",

                                             SqlDbType.Int, 4);
                parameter.Value = model.PeopleId;
                parameters.Add(parameter);
                count++;
            }



            if (model.SectionId_IsEdit)
            {
                strSql.Append(" SectionId = @SectionId,");
                parameter = new SqlParameter("@SectionId",

                                             SqlDbType.Int, 4);
                parameter.Value = model.SectionId;
                parameters.Add(parameter);
                count++;
            }



            if (model.Ext1_IsEdit)
            {
                strSql.Append(" Ext1 = @Ext1,");
                parameter = new SqlParameter("@Ext1",

                                             SqlDbType.VarChar, 50);
                parameter.Value = model.Ext1;
                parameters.Add(parameter);
                count++;
            }

            if (count > 0)
            {
                strSql.Remove(strSql.Length - 1, 1);
            }
            if (count == 0)
            {
                return(false);
            }
            strSql.Append(" where Id=@Id ");
            // 将参数泛形集合转传为数组
            SqlParameter[] args = new SqlParameter[parameters.Count];
            parameters.CopyTo(args, 0);
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), args);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }