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

            strSql.Append("update UserGroup set ");
            strSql.Append("UserGroupRemark=@UserGroupRemark");
            strSql.Append(" where UserGroupId=@UserGroupId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserGroupRemark", SqlDbType.Text),
                new SqlParameter("@UserGroupId",     SqlDbType.Int,4),
                new SqlParameter("@UserGroupName",   SqlDbType.VarChar, 20)
            };
            parameters[0].Value = model.UserGroupRemark;
            parameters[1].Value = model.UserGroupId;
            parameters[2].Value = model.UserGroupName;

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

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

            strSql.Append("insert into UserGroup(");
            strSql.Append("UserGroupName,UserGroupRemark)");
            strSql.Append(" values (");
            strSql.Append("@UserGroupName,@UserGroupRemark)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserGroupName",   SqlDbType.VarChar, 20),
                new SqlParameter("@UserGroupRemark", SqlDbType.Text)
            };
            parameters[0].Value = model.UserGroupName;
            parameters[1].Value = model.UserGroupRemark;

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

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

            strSql.Append("select  top 1 UserGroupId,UserGroupName,UserGroupRemark from UserGroup ");
            strSql.Append(" where UserGroupId=@UserGroupId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@UserGroupId", SqlDbType.Int, 4)
            };
            parameters[0].Value = UserGroupId;

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

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