Exemple #1
0
        public bool update(User user, int uId)
        {
            List <SqlParameter> parameters = new List <SqlParameter>();
            StringBuilder       sql        = new StringBuilder();

            sql.Append("update [user] set");

            if (!user.Username.Equals(""))
            {
                sql.Append(" username=@Username,");
                SqlParameter Username = new SqlParameter("@Username", SqlDbType.VarChar, 50);
                Username.Value = user.Username;
                parameters.Add(Username);
            }
            if (!user.Password.Equals(""))
            {
                sql.Append(" password=@Password,");
                SqlParameter Password = new SqlParameter("@Password", SqlDbType.VarChar, 50);
                Password.Value = user.Password;
                parameters.Add(Password);
            }
            if (user.Age != -1)
            {
                sql.Append(" age=@Age,");
                SqlParameter Age = new SqlParameter("@Age", SqlDbType.Int, 3);
                Age.Value = user.Age;
                parameters.Add(Age);
            }
            if (user.Sex != -1)
            {
                sql.Append(" sex=@Sex,");
                SqlParameter Sex = new SqlParameter("@Sex", SqlDbType.Int, 1);
                Sex.Value = user.Sex;
                parameters.Add(Sex);
            }
            if (!user.Sign.Equals(""))
            {
                sql.Append(" sign=@Sign,");
                SqlParameter Sign = new SqlParameter("@Sign", SqlDbType.VarChar, 200);
                Sign.Value = user.Sign;
                parameters.Add(Sign);
            }
            if (user.Photo != null)
            {
                sql.Append(" photo=@Photo,");
                SqlParameter Photo = new SqlParameter("@photo", SqlDbType.Image);
                Photo.Value = user.Photo;
                parameters.Add(Photo);
            }
            if (!user.LastLoginIp.Equals(""))
            {
                sql.Append(" last_login_ip=@LastLoginIp,");
                SqlParameter LastLoginIp = new SqlParameter("@LastLoginIp", SqlDbType.VarChar, 50);
                LastLoginIp.Value = user.LastLoginIp;
                parameters.Add(LastLoginIp);
            }
            if (user.LastLoginTime != null)
            {
                sql.Append(" last_login_time=@LastLoginTime,");
                SqlParameter LastLoginTime = new SqlParameter("@LastLoginTime", SqlDbType.VarChar, 50);
                LastLoginTime.Value = user.LastLoginTime;
                parameters.Add(LastLoginTime);
            }
            if (user.Status != -1)
            {
                sql.Append(" status=@Status,");
                SqlParameter Status = new SqlParameter("@Status", SqlDbType.Int, 1);
                Status.Value = user.Status;
                parameters.Add(Status);
            }


            string sqlStr = sql.ToString();

            sqlStr  = sqlStr.Substring(0, sqlStr.Length - 1);
            sqlStr += " where u_id=@Uid";
            SqlParameter UId = new SqlParameter("@Uid", SqlDbType.Int, 10);

            UId.Value = uId;
            parameters.Add(UId);

            Console.WriteLine("查询语句。。。。。。。。。。。。。。。" + sqlStr);
            int row = SqlDbHelper.ExecuteNoQuery(sqlStr, CommandType.Text, parameters);

            if (row >= 1)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }