DataAccessLayer.DataBase.NameById C# (CSharp) Method

NameById() public method

public NameById ( System.Guid accountId ) : string
accountId System.Guid
return string
        public string NameById(Guid accountId)
        {
            var queryString =
               "SELECT accounts.login " +
               "FROM [dbo].accounts " +
               "WHERE accounts.accountid = @accountid;";

            using (SqlConnection connection = new SqlConnection(_connectionString))
            {
                var command = new SqlCommand(queryString, connection);
                command.Parameters.AddWithValue("accountid", accountId);

                connection.Open();
                var reader = command.ExecuteReader();

                if (reader == null)
                    return null;
                var str = "";
                while (reader.Read())
                    str = (string)reader[0];
                return str;
            }
        }