Re: Way to change from Username to Display Name?

  •  08-17-2009, 6:57 AM

    Re: Way to change from Username to Display Name?

     
    dhananjaym:
    Could you throw some light on how you did it.
     
    Cheers!
     
    Since my issue was within the chatrooms, I wrote a GetUserDiplayName function into the SampleProvider.cs file. 
    public string GetDisplayName(string username)
            {
                SqlConnection conn = this.CreateConnection();
                String tusername = "User:" + username;
                SqlCommand cmd = new SqlCommand("SELECT DisplayName from CuteChat4_User WHERE UserID=@Username", conn);
                SqlParameter paraUsername = cmd.Parameters.Add("@Username", SqlDbType.NVarChar);
                paraUsername.Value = tusername;
                try
                {
                    conn.Open();
                    string tmp = (String)cmd.ExecuteScalar();
                    if (tmp.Length < 5) //in case they've never set a display name, but let "admin" in
                    {
                        return username;
                    }
                    if (tmp.ToLower() != username.ToLower())
                    {
                        return tmp;
                    }
                    else
                    {
                        return username;
                    }
                }
                catch
                {
                    return username;
                }
                finally
                {
                    conn.Close();
                }
            }
View Complete Thread